好吧,我有点好奇,所以我在问完问题后就自己测试了这三个;-)
好吧,这不是一个非常严肃的评论,但我可以说的是:
我尝试了工具使用默认设置(这很重要,因为您几乎可以选择检查规则)以下脚本:
#!/usr/local/bin/python
# by Daniel Rosengren modified by e-satis
import sys, time
stdout = sys.stdout
BAILOUT = 16
MAX_ITERATIONS = 1000
class Iterator(object) :
def __init__(self):
print 'Rendering...'
for y in xrange(-39, 39):
stdout.write('\n')
for x in xrange(-39, 39):
if self.mandelbrot(x/40.0, y/40.0) :
stdout.write(' ')
else:
stdout.write('*')
def mandelbrot(self, x, y):
cr = y - 0.5
ci = x
zi = 0.0
zr = 0.0
for i in xrange(MAX_ITERATIONS) :
temp = zr * zi
zr2 = zr * zr
zi2 = zi * zi
zr = zr2 - zi2 + cr
zi = temp + temp + ci
if zi2 + zr2 > BAILOUT:
return i
return 0
t = time.time()
Iterator()
print '\nPython Elapsed %.02f' % (time.time() - t)
因此:
-
PyChecker
比较麻烦,因为它要编译模块来分析它。如果您不希望代码运行(例如,它执行 SQL 查询),那就不好了。
-
PyFlakes
应该是轻的。事实上,它认为代码是完美的。我正在寻找一些非常严重的东西,所以我认为我不会去做。
-
PyLint
非常健谈,对代码的评分为 3/10(天哪,我是个肮脏的编码员!)。
优点PyLint
:
- 非常描述性和准确的报告。
- 检测一些代码气味。这里它告诉我放弃我的类来编写带有函数的东西,因为 OO 方法在这种特定情况下毫无用处。我知道一些事情,但从未想过计算机会告诉我:-p
- 完全更正的代码运行速度更快(没有类,没有引用绑定......)。
- 由法国团队制作。好吧,这并不是对每个人都有好处,但我喜欢它;-)
Pylint 的缺点:
- 有些规则确实很严格。我知道你可以更改它,并且默认值是匹配 PEP8,但是写“for x in seq”是犯罪行为吗?显然是的,因为你不能写少于 3 个字母的变量名。我会改变这一点。
- 非常非常健谈。准备好用你的眼睛。
更正的脚本(带有惰性文档字符串和变量名称):
#!/usr/local/bin/python
# by Daniel Rosengren, modified by e-satis
"""
Module doctring
"""
import time
from sys import stdout
BAILOUT = 16
MAX_ITERATIONS = 1000
def mandelbrot(dim_1, dim_2):
"""
function doc string
"""
cr1 = dim_1 - 0.5
ci1 = dim_2
zi1 = 0.0
zr1 = 0.0
for i in xrange(MAX_ITERATIONS) :
temp = zr1 * zi1
zr2 = zr1 * zr1
zi2 = zi1 * zi1
zr1 = zr2 - zi2 + cr1
zi1 = temp + temp + ci1
if zi2 + zr2 > BAILOUT:
return i
return 0
def execute() :
"""
func doc string
"""
print 'Rendering...'
for dim_1 in xrange(-39, 39):
stdout.write('\n')
for dim_2 in xrange(-39, 39):
if mandelbrot(dim_1/40.0, dim_2/40.0) :
stdout.write(' ')
else:
stdout.write('*')
START_TIME = time.time()
execute()
print '\nPython Elapsed %.02f' % (time.time() - START_TIME)
感谢吕迪格·沃尔夫 https://stackoverflow.com/questions/1428872/pylint-pychecker-or-pyflakes/1431749#1431749,我发现pep8
正如它的名字所暗示的那样:匹配 PEP8。它发现了一些 Pylint 没有发现的语法禁忌。但 Pylint 发现了一些与 PEP8 没有明确关联但很有趣的东西。这两种工具都很有趣并且互补。
最终我将使用两者,因为它们确实很容易安装(通过包或安装工具)并且输出文本很容易链接。
让您了解一下他们的输出:
pep8:
./python_mandelbrot.py:4:11: E401 multiple imports on one line
./python_mandelbrot.py:10:1: E302 expected 2 blank lines, found 1
./python_mandelbrot.py:10:23: E203 whitespace before ':'
./python_mandelbrot.py:15:80: E501 line too long (108 characters)
./python_mandelbrot.py:23:1: W291 trailing whitespace
./python_mandelbrot.py:41:5: E301 expected 1 blank line, found 3
Pylint:
************* Module python_mandelbrot
C: 15: Line too long (108/80)
C: 61: Line too long (85/80)
C: 1: Missing docstring
C: 5: Invalid name "stdout" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C: 10:Iterator: Missing docstring
C: 15:Iterator.__init__: Invalid name "y" (should match [a-z_][a-z0-9_]{2,30}$)
C: 17:Iterator.__init__: Invalid name "x" (should match [a-z_][a-z0-9_]{2,30}$)
[...] and a very long report with useful stats like :
Duplication
-----------
+-------------------------+------+---------+-----------+
| |now |previous |difference |
+=========================+======+=========+===========+
|nb duplicated lines |0 |0 |= |
+-------------------------+------+---------+-----------+
|percent duplicated lines |0.000 |0.000 |= |
+-------------------------+------+---------+-----------+