如何在python源代码中配置pylint

时间:2012-09-24 20:59:27

标签: python suppress-warnings pylint

是否可以在python源代码本身中禁用某些pylint错误/警告?

3 个答案:

答案 0 :(得分:13)

def foo():
    print "000000000000000000000000000000000000000000000000000000000000000000000000000"
print "111111111111111111111111111111111111111111111111111111111111111111111111111"

pylint输出:

C:  2: Line too long (87/80)
C:  3: Line too long (83/80)
C:  1: Missing docstring
C:  1:foo: Black listed name "foo"
C:  1:foo: Missing docstring

添加评论“#pylint:disable = CODE”,代码为“Line too long”消息 - C0301:

def foo():
    # pylint: disable=C0301
    print "000000000000000000000000000000000000000000000000000000000000000000000000000"
print "111111111111111111111111111111111111111111111111111111111111111111111111111"

pylint输出:

I:  2: Locally disabling C0301
C:  4: Line too long (83/80)
C:  1: Missing docstring
C:  1:foo: Black listed name "foo"
C:  1:foo: Missing docstring

答案 1 :(得分:8)

@kalgasnik提到的#pylint:disable语法是正确的。您可以在Pylint FAQ(您的问题是meth2

中找到有关此内容的更多信息

答案 2 :(得分:5)

在eclipse ide中,使用pydev,您可以在代码行之后添加注释,格式为# IGNORE:_ID_。我不知道这是否也适用于其他程序。 例如:

import something  # IGNORE:W0611