shantanuo
shantanuo

Reputation: 32316

remove non-breaking space from python code

I get an error while trying to import a module:

from sklearn.model_selection import train_test_split 

SyntaxError: invalid character in identifier

This is because there is a non breaking space at the end of the string:

x='from sklearn.model_selection import train_test_split '

x[-1:]

'\xa0'

I can replace that space and then copy-paste the code like this:

import unicodedata
new_str = unicodedata.normalize("NFKD", x)

print (new_str)

This new string have no issues:

from sklearn.model_selection import train_test_split

But I will like to know if ipython notebook has built-in function to correct such issues.

Upvotes: 1

Views: 1501

Answers (3)

furkanayd
furkanayd

Reputation: 872

This subject discussed on Github page of jupyter-notebook.

Links :

Strip trailing whitespace (Closed)

Trailing whitespace in editor (Open)

Trailing whitespace in editor (Open)

Upvotes: 1

cindy
cindy

Reputation: 474

x='from sklearn.model_selection import train_test_split '
print(x.strip())

Upvotes: 0

Harish Vutukuri
Harish Vutukuri

Reputation: 1150

There is no such built-in function in iPython. Custom magic commands can be created in iPython using this guide

Upvotes: 1

Related Questions