<p>嗯,我有点好奇,所以我刚问完问题就自己测试了3个;-)</p>
<p>好吧,这不是一个很严肃的评论,但我可以说:</p>
<p>我在以下脚本中使用默认设置尝试了工具<strong>(这很重要,因为您几乎可以选择您的检查规则):</p>
<pre><code>#!/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)
</code></pre>
<p><strong>因此:</strong></p>
<ul>
<li><code>PyChecker</code>很麻烦,因为它编译模块来分析它。如果你不想让你的代码运行(例如,它执行一个SQL查询),那就糟糕了。</li>
<li><code>PyFlakes</code>应该是lite。事实上,它认为代码是完美的。我在找很严重的东西,所以我想我不会去的。</li>
<li><code>PyLint</code>一直很健谈,对代码的评分是3/10(天哪,我是个肮脏的程序员!)。</li>
</ul>
<p><strong>strong<code>PyLint</code>的点:</strong></p>
<ul>
<li>非常描述性和准确的报告。</li>
<li>检测一些代码气味。在这里,它告诉我不要用函数编写类,因为在这种特定情况下,OO方法是无用的。我知道一些事情,但从没想到电脑会告诉我-p</li>
<li>完全正确的代码运行得更快(没有类,没有引用绑定…)。</li>
<li>法国队制造的。好吧,这对每个人来说都不是好事,但我喜欢;-)</li>
</ul>
<p><strong>Cons of<code>PyLint</code>:</strong></p>
<ul>
<li>有些规则真的很严格。我知道你可以更改它,默认值是匹配PEP8,但是写“for x in seq”是不是太犯法了?显然是的,因为你不能写一个少于3个字母的变量名。我会改变的。</li>
<li>非常健谈。准备好用你的眼睛。</li>
</ul>
<p>更正的脚本(使用惰性文档字符串和变量名):</p>
<pre><code>#!/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)
</code></pre>
<p><strong>编辑:</strong></p>
<p>多亏了鲁迪格·沃尔夫,我发现<code>pep8</code>正是它的名字所暗示的:匹配的PEP8。它发现了一些PyLint没有的语法no。但是<code>PyLint</code>发现了一些与PEP8没有特别联系但很有趣的东西。这两种工具都很有趣,而且是互补的。</p>
<p>最后,我将使用这两种方法,因为安装非常容易(通过包或安装工具),而且输出文本很容易链接。</p>
<p>为了让您了解它们的输出:</p>
<p><strong>pep8</strong>:</p>
<pre><code>./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
</code></pre>
<p><strong>PyLint</strong>:</p>
<pre><code>************* 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 |= |
+-------------------------+------+---------+-----------+
</code></pre>