python - 从 python 代码中删除不间断空格
问题描述
尝试导入模块时出现错误:
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 是否具有纠正此类问题的内置功能。
解决方案
iPython 中没有这样的内置函数。可以使用本指南在 iPython 中创建自定义魔法命令
推荐阅读
- reporting-services - 如何为 SSRS 中的所有报告订阅提供一个中心位置?
- c# - 我无法让我的精灵降落在我的平台之上
- python - 在 Django 设置中找不到使用 venv 安装的包
- html - primeng p-tree中的全行选择
- r - Shiny:使用 fileInput() 和 selectizeInput() 自动化 Web 应用程序
- php - 如何确保一个特定的 PHPUnit 测试用例在其他测试用例之前运行?
- linux - 从bash中的列转换日期
- git - GitLab 致命:无法访问:请求的 URL 返回错误:503
- c# - C# WPF ListView 没有正确删除项目
- sharepoint - Microsoft Sharepoint API - 通过共享 URL 访问共享文件夹