有没有一种简单的方法来检查正在编写的iPython notebook代码是否符合PEP8?
发布于 2014-10-05 21:27:39
使用以下命令安装ipython notebook的pep8扩展:
%install_ext https://raw.githubusercontent.com/SiggyF/notebooks/master/pep8_magic.py
有关更多信息,请参阅the official docs。
之后,使用%%pep8
Cell魔术函数检查特定单元格的pep8样式。
请注意,必须将其放入每个需要强制执行pep8检查的单元中。
请参阅this example。
发布于 2021-12-13 14:03:28
我喜欢使用black
linter和pre-commit
git hooks的组合来保持我的笔记本整洁(在每次提交时自动插入)。
pip install pre-commit "black[jupyter]"
# <-- create your .pre-commit-config.yaml
pre-commit install
black {source_file_or_directory}
# your notebooks will be linted whenever you commit now
有关如何设置.pre-commit-config.yaml
的说明,请参阅black docs)和pre-commit docs。
发布于 2019-12-03 21:23:05
您可以包含我的脚本的某些部分(下面的链接),以查看哪些代码行需要特定的PEP8更正。你也可以独立运行它。
该脚本基于flake8将PEP8注释包含到py文件代码中。这使得它很容易立即跳到需要更正样式的地方。
https://stackoverflow.com/questions/26126853
复制相似问题