尝试导入模块时出现错误:
from sklearn.model_selection import train_test_split
SyntaxError:标识符中的字符无效
这是因为字符串的末尾有一个不间断的空格:
x='from sklearn.model_selection import train_test_split '
x[-1:]
'\ xa0'
我可以替换该空间,然后复制粘贴如下代码:
import unicodedata
new_str = unicodedata.normalize("NFKD",x)
print (new_str)
此新字符串没有问题:
从sklearn.model_selection导入train_test_split
但是我想知道ipython笔记本是否具有内置功能来纠正此类问题。