Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

python - Verifying PEP8 in iPython notebook code

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

enter image description here

To turn off the auto-compliance-checking run:

%pycodestyle_off or %flake8_off


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...