Verifying PEP8 in iPython notebook code

后端 未结 4 1938
醉酒成梦
醉酒成梦 2020-12-12 22:16

Is there an easy way to check that iPython notebook code, while it\'s being written, is compliant with PEP8?

4条回答
  •  醉话见心
    2020-12-12 23:09

    Make sure you've the module pycodestyle or flake8 to be able to check your code against the style guides. Then enable the magic function by using the pycodestyle_magic module (github repo):

    pip install flake8 pycodestyle_magic
    
    • first load the magic in a Jupyter Notebook cell:

    %load_ext pycodestyle_magic

    • and then turn on the magic to do compliance checking for each cell using:

    %pycodestyle_on or %flake8_on

    depending against which style guide you want to check.

    To turn off the auto-compliance-checking run:

    %pycodestyle_off or %flake8_off

提交回复
热议问题