1、Pylint是什麼

pylint是一個Python原始碼中查詢bug的工具,能找出錯誤,和程式碼規範的執行。也就是你的程式碼有Error錯誤的時候能找出來錯誤,沒有錯誤的時候,能根據Python程式碼規範給你建議修改程式碼,讓程式碼變更美觀。
 
2、安裝pylint
 pip3 install pylint
3、查詢pylint的安裝地址
$ which pylint
/Library/Frameworks/Python.framework/Versions/3.9/bin/pylint
 
4、Pycharm使用Pylint工具
 
1)Pycharm --> Preferences --> Tools --> External Tools --> + 
 
 
Program:pylint的地址,可以通過which pylint找到地址
Arguments:pylint執行的引數
 
2)使用
 
 
 
3)得到的結果
 
************* Module 704
leetcode/704.py:28:0: C0305: Trailing newlines (trailing-newlines) #文尾有多餘的行
leetcode/704.py:1:0: C0114: Missing module docstring (missing-module-docstring) # 指令碼首行沒有添加註釋
leetcode/704.py:4:11: W0621: Redefining name 'nums' from outer scope (line 23) (redefined-outer-name) #變數名字與函式引數名字不能一樣
leetcode/704.py:4:28: W0621: Redefining name 'target' from outer scope (line 24) (redefined-outer-name) #變數名字與函式引數名字不能一樣
leetcode/704.py:4:0: C0116: Missing function or method docstring (missing-function-docstring) #函式缺少註釋,註釋要放在函式的第一行而不是def的上面
5、pylint的5種資訊型別
 
Output:
   Using the default text output, the message format is :
  MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE
  There are 5 kind of message types :
  * (C) convention, for programming standard violation
  * (R) refactor, for bad code smell
  * (W) warning, for python specific problems
  * (E) error, for probable bugs in the code
  * (F) fatal, if an error occurred which prevented pylint from doing further processing.
 
* (C) 約定,用於違反程式設計標準
* (R) 重構,針對糟糕的程式碼味道
* (W) 警告,針對 python 特定問題
* (E) 錯誤,用於程式碼中可能的錯誤
* (F) 致命的,如果發生錯誤導致 pylint 無法進行進一步處理。
 
6、更多的pylint資訊
 
1)可以通過命令列獲取
 
pylint --list-msgs

2)官網

http://pylint.pycqa.org/en/latest/#