分析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分析評估程式碼質量
- Python 程式碼的質量控制之 flake8 & PylintPython
- Pylint:讓你的 Python 程式碼保持一致Python
- Pylint:更高層級的 Python 樣式強制程式Python
- 效能最快的程式碼分析工具,Ruff 正在席捲 Python 圈!Python
- 一個好程式碼的工具:Video Studio AIIDEAI
- 程式碼分析工具小結
- Python 程式碼混淆工具概述Python
- 我寫的 Python 程式碼,同事都說好Python
- ABAP程式碼分析工具 - 事務碼SQF
- Python程式碼混淆工具,Python原始碼保密、加密、混淆Python原始碼加密
- python 3.6如何儲存編輯好的程式碼Python
- Python用什麼工具好?Python工具推薦!Python
- python程式碼檢查工具(靜態程式碼審查)Python
- Electrum 比特幣錢包的 Python 程式碼分析比特幣Python
- PHP工具箱:PHPStan —— PHP 靜態程式碼分析工具PHP
- 好程式設計師Python培訓分享Python爬蟲工具列表大全程式設計師Python爬蟲
- AbsInt — 確保程式碼安全的靜態效能分析工具
- 好工具,SWOT分析大解密!解密
- Python用什麼工具好?Python開發工具推薦!Python
- 5種好用的Python工具!Python學習分析Python
- 零程式碼做分析報表的bi軟體才是好軟體
- 碼農深耕 - 什麼樣的程式碼才是好程式碼?
- Python程式碼混淆處理工具:Intensio-ObfuscatorPython
- 好程式設計師Python培訓分享開發工具推薦程式設計師Python
- Python和Java哪個好?分析!PythonJava
- 好程式設計師Python培訓分析 學完Python好不好就業程式設計師Python就業
- ABAP程式碼靜態分析工具SQF - Support Query FrameworkFramework
- 什麼樣的程式碼稱得上是好程式碼?
- 靜態程式碼分析的這些好處,我竟然都不知道?
- CCMixer/CodeMixer工具,完美替代ChaosTool,iOS新增垃圾程式碼工具,程式碼混淆工具,程式碼生成器,史上最好用的垃圾程式碼新增工具,自己開發的小工具iOS
- 如何寫好程式碼
- 如何寫好程式碼?
- 好的程式碼可以自己說話!
- 好的程式碼很容易刪除!
- CodeMixer完美替代ChaosTool ,iOS新增垃圾程式碼工具,程式碼混淆工具,程式碼生成器,史上最好用的垃圾程式碼新增工具,自己開發的小工具...iOS
- Python——cProfile(程式分析)Python
- Drafter: 一個在iOS專案中分析程式碼結構的工具RaftiOS