在Ipython中使用Pylint(Jupyter-Notebook) [英] Using Pylint in Ipython (Jupyter-Notebook)
问题描述
我想在使用Jupyter-Notebook时运行Pylint或任何等效版本.有没有办法以这种方式安装和运行Pylint?
I want to run Pylint or any equivalent while using Jupyter-Notebook. Is there a way to install and run Pylint this way?
推荐答案
pycodestyle 与Jupyter Notebook的pylint
等效,它可以根据PEP8
样式指南检查代码.
pycodestyle is an equivalent of pylint
for Jupyter Notebook which is able to check your code against the PEP8
style guide.
首先,您需要通过键入以下命令在jupyter notebook
中安装pycodestyle
,
First, you need to install the pycodestyle
in jupyter notebook
by typing this command,
!pip install pycodestyle pycodestyle_magic
在jupyter笔记本的单元格中运行此命令. 成功安装后,您必须像这样在Jupyter Notebook单元中加载魔法,
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
然后,您必须在要根据PEP8
标准调查代码的单元格中使用pycodestyle
.
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
输出:pycodestyle
会给您此消息,
2:2: E225 missing whitespace around operator
另一个例子,
%%pycodestyle
def square_of_number(
num1, num2, num3,
num4):
return num1**2, num2**2, num3**2, num4**2
输出:
2:1: E302 expected 2 blank lines, found 0
3:23: W291 trailing whitespace
这篇关于在Ipython中使用Pylint(Jupyter-Notebook)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!