Using Pylint in Ipython (Jupyter-Notebook)

狂风中的少年 提交于 2019-12-05 12:58:56

问题


I want to run Pylint or any equivalent while using Jupyter-Notebook. Is there a way to install and run Pylint this way?


回答1:


pycodestyle is an equivalent of pylint for Jupyter Notebook which is able to check your code against the PEP8 style guide.

First, you need to install the pycodestyle in jupyter notebook by typing this command,

!pip install pycodestyle pycodestyle_magic

Run this command in a cell of jupyter notebook. After successful installation, you have to load the magic in a Jupyter Notebook cell like this,

%load_ext pycodestyle_magic

Then, you have to use pycodestyle in a cell in which you want to investigate your code against PEP8 standards.

Below are some examples for more and clear understanding,

%%pycodestyle
a=1

Output: pycodestyle will give you this message,

2:2: E225 missing whitespace around operator

Another example,

%%pycodestyle
def square_of_number(
     num1, num2, num3, 
     num4):
    return num1**2, num2**2, num3**2, num4**2

Output:

2:1: E302 expected 2 blank lines, found 0
3:23: W291 trailing whitespace



回答2:


No, you can not introduce pylint into jupyter notebook.

If you want to check your code style, you need jupyter notebook's extensions.

Possible this one:

https://github.com/ipython-contrib/jupyter_contrib_nbextensions/tree/master/src/jupyter_contrib_nbextensions/nbextensions/code_prettify



来源:https://stackoverflow.com/questions/50358327/using-pylint-in-ipython-jupyter-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!