首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >皮林特,PyChecker还是PyFlakes?

皮林特,PyChecker还是PyFlakes?
EN

Stack Overflow用户
提问于 2009-09-15 18:24:15
回答 2查看 143K关注 0票数 404

我想从以下几个方面得到一些反馈:

  • features;
  • adaptability;
  • ease的使用和学习曲线.
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-09-15 19:21:39

嗯,我有点好奇,所以我刚问完这个问题,就亲自测试了这三个人。

好吧,这不是一个很严肃的评论,但我可以这么说:

我在下面的脚本中尝试了带有默认设置的工具(这很重要,因为您几乎可以选择检查规则):

代码语言:javascript
复制
#!/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查询),那么bad.
  • PyFlakes应该是轻量级的。实际上,它认为代码是完美的。我正在寻找一些相当严重的东西,所以我不认为我会去做,因为it.
  • PyLint一直很健谈,并且对代码3/10进行了评级(天哪,我是一个肮脏的程序员!)

PyLint**:** 的优点

report.

  • Detect
  • 非常具有描述性和准确性,有些代码闻起来很难闻。在这里,它告诉我不要使用函数编写类,因为在这种特殊情况下,OO方法是无用的。我知道一些事情,但从来没有想到计算机会告诉我:-p
  • 完全修正的代码运行得更快(没有类,法国团队没有引用
  • )。好吧,这不是每个人的优点,但我喜欢;-)

Cons of Pylint:

  • ,有些规则真的很严格。我知道您可以更改它,默认情况是与PEP8匹配,但是写'for‘(在seq中)是一种犯罪吗?显然,是的,因为你不能用少于3个字母来写一个变量名。我会改变这一点的。
  • 非常健谈。准备好用你的眼睛。--

更正的脚本(带有延迟的文档字符串和变量名):

代码语言:javascript
复制
#!/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)

Thanks to Rudiger Wolf,我发现了pep8,它做的正是它的名字:匹配PEP8。它发现有几个语法不是Pylint所没有的。但是,Pylint发现了一些与PEP8没有特别关联但很有趣的东西。这两种工具都是有趣和互补的。

最后,我将使用这两种方式,因为它们非常容易安装(通过包或setuptools),并且输出文本非常容易链接。

让你对它们的输出有一点了解:

pep8

代码语言:javascript
复制
./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

代码语言:javascript
复制
************* 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    |=          |
+-------------------------+------+---------+-----------+
票数 292
EN

Stack Overflow用户

发布于 2009-09-16 08:45:22

pep8最近被添加到PyPi中。

  • pep8 - Python样式指南检查器
  • pep8是一个工具,可以根据PEP 8.

中的一些样式约定检查您的Python代码。

现在,通过pep8检查代码是非常容易的。

请参阅http://pypi.python.org/pypi/pep8

票数 95
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1428872

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档