使用以下命令:html
pip3 install pylintpython
安裝完後能夠看到在你的python3的目錄底下的Scripts目錄下有pylint.exe了ui
而後就能夠使用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:spa
進入PyCharm,從菜單欄,依次進入: File -> Settings -> Tools -> External Tools。code
「+」,進行添加。須要填寫的部分分別是:「Name」,「Tool Settings -> Programs」、「Tool Settings -> Parameters」、「Tool Settings -> Working directory」。orm
配置完畢,選擇一個Python程序,右鍵點擊,快捷菜單中會有「Extensions Tools -> Pylint」,點擊運行便可。輸出結果在執行程序結果的窗口(IDE下半部分)。htm
Pylint的默認輸出格式是原始文
本(raw text)格式 ,能夠經過 -f <format>,--output-format=<format> 來指定別的輸出格式如
html等等。在
Pylint的輸出中有以下兩個部分:源代碼分析部分
和報告部分。
blog
源代碼分析部分:ip
對於每個 Python 模塊,Pylint 的結果中首先顯示一些"*"字符 , 後面緊跟模塊的名字,而後是一系列的 message, message 的格式以下:
1
|
MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE
|
MESSAGE_TYPE 有以下幾種:
(C) 慣例。違反了編碼風格標準
(R) 重構。寫得很是糟糕的代碼。
(W) 警告。某些 Python 特定的問題。
(E) 錯誤。極可能是代碼中的錯誤。
(F) 致命錯誤。阻止 Pylint 進一步運行的錯誤。