2014-09-30 121 views

回答

12

使用以下命令安装了IPython的笔记本PEP8扩展:

%install_ext https://raw.githubusercontent.com/SiggyF/notebooks/master/pep8_magic.py 

参考the official docs获取更多信息。

之后,使用%%pep8细胞魔术功能检查您的特定细胞pep8造型。

请注意,这必须放在每个需要执行pep8检查的单元格中。

参照this example

+6

install_ext已被弃用,删除。现在需要在PyPI上发布扩展,并使用pip进行安装。 – Matt 2017-02-07 19:43:09

+0

pep8已弃用,扩展名现在需要在PyPi上发布,请参阅https://stackoverflow.com/a/47204361/2459096或srcoll down – Mattijn 2017-11-09 14:29:13

4

在这种情况下,任何人帮助,我使用的是:更改保存到笔记本

  • flake8 -告诉flake8采取从标准
  • --ignore=W391输入时

    conttest "jupyter nbconvert notebook.ipynb --stdout --to script | flake8 - --ignore=W391"

    • conttest重播 - 这是因为jupyter nbconvert的输出似乎总是在文件末尾有一个“空行”,所以我不希望flake8抱怨这一点。

    我遇到降价单元问题(其线长可能合理很长,但是):ignore markdown cells in `jupyter nbconvert` with `--to script`

  • 3

    确保您已经使模块pycodestyle能够根据样式指南检查您的代码。

    pip install pycodestyle 
    pip install pycodestyle_magic 
    
    • 第一负载魔术在Jupyter笔记本电池:然后使用pycodestyle_magic模块使神奇的功能

    %load_ext pycodestyle_magic

    • ,然后使用该函数在细胞检查是否符合pycodestyle

    %%pycodestyle

    enter image description here

    +0

    迄今为止工作正常,谢谢!只需确保安装这两个软件包,pycodestyle和pycodestyle_magic。从屏幕上看不太清楚(起初我没有看到第一个代码注释) – hmrc87 2017-11-09 18:54:15

    +1

    改写了第一句话,很高兴这很有帮助 – Mattijn 2017-11-09 20:22:29