1

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.

shantanuo
  • 31,689
  • 78
  • 245
  • 403

3 Answers3

1

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

Harish Vutukuri
  • 1,092
  • 6
  • 14
  • Is there any way to write a trigger that will run a function when a cell is executed? I do not want to add @cell_magic at the beginning of every cell as suggested. The magic should happen on the fly :) – shantanuo Nov 26 '19 at 10:30
  • You can write a jquery something like this: https://stackoverflow.com/a/38856870/6537262 – Harish Vutukuri Nov 26 '19 at 11:06
  • That code will autorun all cells on notebook-load. I am trying to autorun on single cell execution. – shantanuo Nov 27 '19 at 06:45
1

This subject discussed on Github page of jupyter-notebook.

Links :

Strip trailing whitespace (Closed)

Trailing whitespace in editor (Open)

Trailing whitespace in editor (Open)

furkanayd
  • 811
  • 7
  • 19
0
x='from sklearn.model_selection import train_test_split '
print(x.strip())
cindy
  • 476
  • 6
  • 8