Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 342
Seanny123 Avatar asked Sep 30 '14 17:09

Seanny123


People also ask

Does Jupyter support code autocompletion?

Enable autocomplete featureTo enable code autocomplete in Jupyter Notebook or JupyterLab, you just need to hit the Tab key while writing code. Jupyter will suggest a few completion options. Navigate to the one you want with the arrow keys, and hit Enter to choose the suggestion.

Does Jupyter Notebook have SymPy?

SymPy can be used from a Python module, or interactively in Jupyter/IPython. In the Notebook, all mathematical expressions are displayed with LaTeX, thanks to the MathJax JavaScript library.

Does Jupyter lab have intellisense?

By default, Jupyter notebooks do not have intellisense.


1 Answers

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

like image 124
Mattijn Avatar answered Sep 21 '22 12:09

Mattijn