Python3 安装pylint 及与PyCharm关联

使用如下命令:

pip3 install pylint

 

安装完后可以看到在你的python3的目录底下的Scripts目录下有pylint.exe了

然后就可以使用pylint 评估你的代码了,如:

E:\Learning\AWS\Python>pylint learning.py
No config file found, using default configuration
************* Module learning
C:  7, 0: No space allowed before bracket
print (queue.pop())
      ^ (bad-whitespace)
C:  8, 0: No space allowed before bracket
print (queue)
      ^ (bad-whitespace)
C:  9, 0: No space allowed before bracket
print (queue.popleft())
      ^ (bad-whitespace)
C: 23, 0: No space allowed before bracket
    print ("row:")
          ^ (bad-whitespace)
C: 24, 0: No space allowed before bracket
    print (row)
          ^ (bad-whitespace)
C: 34, 0: Trailing newlines (trailing-newlines)
C:  1, 0: Missing module docstring (missing-docstring)
C:  4, 0: Constant name "queue" doesn't conform to UPPER_CASE naming style (invalid-name)
C: 11, 0: Constant name "freshfruit" doesn't conform to UPPER_CASE naming style (invalid-name)
C: 15, 0: Constant name "matrix" doesn't conform to UPPER_CASE naming style (invalid-name)
C: 30, 0: Constant name "comb" doesn't conform to UPPER_CASE naming style (invalid-name)

-----------------------------------
Your code has been rated at 3.89/10

 

安装完毕可以在PyCharm中关联pylint:

进入PyCharm,从菜单栏,依次进入: File -> Settings -> Tools -> External Tools。

“+”,进行添加。需要填写的部分分别是:“Name”,“Tool Settings -> Programs”、“Tool Settings -> Parameters”、“Tool Settings -> Working directory”。

 

 

配置完毕,选择一个Python程序,右键点击,快捷菜单中会有“Extensions Tools -> Pylint”,点击运行即可。输出结果在执行程序结果的窗口(IDE下半部分)。

 

Pylint 的输出

Pylint的默认输出格式是原始文本(raw text)格式 ,可以通过 -f <format>,--output-format=<format> 来指定别的输出格式如html等等。在Pylint的输出中有如下两个部分:源代码分析部分和报告部分。

源代码分析部分:

对于每一个 Python 模块,Pylint 的结果中首先显示一些"*"字符 , 后面紧跟模块的名字,然后是一系列的 message, message 的格式如下:

1
MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE

MESSAGE_TYPE 有如下几种:

(C) 惯例。违反了编码风格标准

(R) 重构。写得非常糟糕的代码。

(W) 警告。某些 Python 特定的问题。

(E) 错误。很可能是代码中的错误。

(F) 致命错误。阻止 Pylint 进一步运行的错误。

posted on 2018-06-06 16:34  yanzibuaa  阅读(3814)  评论(0编辑  收藏  举报