分析Python程式碼的好工具PyLint
Python code analysis can be a heavy subject, but it can be very helpful in making your programs better. There are several Python code analyzers that you can use to check your code and see if they conform. to standards.
Pylint is probably the most popular. It’s very configurable, customizable and pluggable too. It also checks your code to see if it conforms to PEP8, the official style. guide of Python Core and it looks for programming errors too. We’re going to spend a few minutes looking at some of the things you can do with this handy tool.
Getting Started
Sadly, pylint isn’t included with Python, so you’ll need to go out and download it from Logilab or PyPI. If you have SetupTools installed, then you can install it using easy_install, like this:
Analyzing Your Code
The latest version as of this writing is 0.25.1. Once pylint is installed, you can run it on the command line without any arguments to see what options it accepts. Now we need some code to test with. Since I wrote some crummy code for my PyChecker article last year, we’ll re-use that here and see if pylint picks up the same problems. There should be four issues. Here’s the code:
02.
03.########################################################################
04.class CarClass:
05.""""""
06.
07.#----------------------------------------------------------------------
08.def __init__(self, color, make, model, year):
09."""Constructor"""
10.self.color = color
11.self.make = make
12.self.model = model
13.self.year = year
14.
15.if "Windows" in platform.platform():
16.print "You're using Windows!"
17.
18.self.weight = self.getWeight(1, 2, 3)
19.
20.#----------------------------------------------------------------------
21.def getWeight(this):
22.""""""
23.return "2000 lbs"
Pylint is probably the most popular. It’s very configurable, customizable and pluggable too. It also checks your code to see if it conforms to PEP8, the official style. guide of Python Core and it looks for programming errors too. We’re going to spend a few minutes looking at some of the things you can do with this handy tool.
Getting Started
Sadly, pylint isn’t included with Python, so you’ll need to go out and download it from Logilab or PyPI. If you have SetupTools installed, then you can install it using easy_install, like this:
CODE:
easy_install pylintNow you should have pylint installed and ready to roll!Analyzing Your Code
The latest version as of this writing is 0.25.1. Once pylint is installed, you can run it on the command line without any arguments to see what options it accepts. Now we need some code to test with. Since I wrote some crummy code for my PyChecker article last year, we’ll re-use that here and see if pylint picks up the same problems. There should be four issues. Here’s the code:
CODE:
01.import sys02.
03.########################################################################
04.class CarClass:
05.""""""
06.
07.#----------------------------------------------------------------------
08.def __init__(self, color, make, model, year):
09."""Constructor"""
10.self.color = color
11.self.make = make
12.self.model = model
13.self.year = year
14.
15.if "Windows" in platform.platform():
16.print "You're using Windows!"
17.
18.self.weight = self.getWeight(1, 2, 3)
19.
20.#----------------------------------------------------------------------
21.def getWeight(this):
22.""""""
23.return "2000 lbs"
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-732928/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- a002-pylint 程式碼分析
- 使用PyLint分析評估程式碼質量
- Pylint:讓你的 Python 程式碼保持一致Python
- Python 程式碼的質量控制之 flake8 & PylintPython
- 如何使用 Pylint 來規範 Python 程式碼風格Python
- Pylint:更高層級的 Python 樣式強制程式Python
- 效能最快的程式碼分析工具,Ruff 正在席捲 Python 圈!Python
- 程式碼分析工具小結
- 開發Python的好工具Python
- 我寫的 Python 程式碼,同事都說好Python
- 一個好程式碼的工具:Video Studio AIIDEAI
- ABAP程式碼分析工具 - 事務碼SQF
- Python 程式碼混淆工具概述Python
- python 3.6如何儲存編輯好的程式碼Python
- 常用Java靜態程式碼分析工具的分析與比較Java
- 程式碼分析/統計工具彙總
- Python用什麼工具好?Python工具推薦!Python
- 好工具,SWOT分析大解密!解密
- Python程式碼混淆工具,Python原始碼保密、加密、混淆Python原始碼加密
- python程式碼檢查工具(靜態程式碼審查)Python
- 好程式碼的定義
- python 程式碼格式化工具:YAPFPython
- AbsInt — 確保程式碼安全的靜態效能分析工具
- 編寫一個分析程式碼依賴的工具(一)
- 好程式設計師Python培訓分享Python爬蟲工具列表大全程式設計師Python爬蟲
- Python用什麼工具好?Python開發工具推薦!Python
- 什麼樣的程式碼才算是好程式碼
- 分析mysql慢查詢日誌的好工具--mysqlslaMySql
- PHP工具箱:PHPStan —— PHP 靜態程式碼分析工具PHP
- 零程式碼做分析報表的bi軟體才是好軟體
- 好程式碼、壞程式碼之二
- 好的程式碼習慣 todo
- 何謂“好的程式碼”? (轉)
- Electrum 比特幣錢包的 Python 程式碼分析比特幣Python
- 碼農深耕 - 什麼樣的程式碼才是好程式碼?
- Python和Java哪個好?分析!PythonJava
- 覺得自己程式碼寫得不夠好?那就用 Android 程式碼優化工具吧~Android優化
- 什麼樣的程式碼稱得上是好程式碼?