【发布时间】:2019-11-27 16:58:12
【问题描述】:
尝试导入模块时出现错误:
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 notebook 是否有内置功能来纠正此类问题。
【问题讨论】: