PyCharm选择性忽略PEP8代码风格警告信息

用了几天的PyCharm,发现确实在编写Python代码上非常好用,但有一点体验不太好,就是代码编写时要按照PEP8代码风格编写,不然会有波浪线的警告信息。解决方法如下:

方法一:

将鼠标移到提示的地方,按alt+Enter,选择忽略(Ignore)这个错误即好。

方法二

打开:File - Settings…… - Editor - Inspections

在python下找到 PEP8 coding style violation,在右边下面的Ignore errors里可以添加忽略的警告信息ID,如下:

PEP 8 coding style violation

如E302就是忽略“expected 2 blank lines, found 0”这个警告(出现在我想给方法上面添加注释的时候)。


警告信息对应的ID在http://pep8.readthedocs.io/en/latest/intro.html#configuration中可找到。

原文地址


附录如下:

codesample message
E1Indentation
E101indentation contains mixed spaces and tabs
E111indentation is not a multiple of four
E112expected an indented block
E113unexpected indentation
E114indentation is not a multiple of four (comment)
E115expected an indented block (comment)
E116unexpected indentation (comment)
E121 (*^)continuation line under-indented for hanging indent
E122 (^)continuation line missing indentation or outdented
E123 (*)closing bracket does not match indentation of opening bracket’s line
E124 (^)closing bracket does not match visual indentation
E125 (^)continuation line with same indent as next logical line
E126 (*^)continuation line over-indented for hanging indent
E127 (^)continuation line over-indented for visual indent
E128 (^)continuation line under-indented for visual indent
E129 (^)visually indented line with same indent as next logical line
E131 (^)continuation line unaligned for hanging indent
E133 (*)closing bracket is missing indentation
E2Whitespace
E201whitespace after ‘(‘
E202whitespace before ‘)’
E203whitespace before ‘:’
E211whitespace before ‘(‘
E221multiple spaces before operator
E222multiple spaces after operator
E223tab before operator
E224tab after operator
E225missing whitespace around operator
E226 (*)missing whitespace around arithmetic operator
E227missing whitespace around bitwise or shift operator
E228missing whitespace around modulo operator
E231missing whitespace after ‘,’, ‘;’, or ‘:’
E241 (*)multiple spaces after ‘,’
E242 (*)tab after ‘,’
E251unexpected spaces around keyword / parameter equals
E261at least two spaces before inline comment
E262inline comment should start with ‘# ‘
E265block comment should start with ‘# ‘
E266too many leading ‘#’ for block comment
E271multiple spaces after keyword
E272multiple spaces before keyword
E273tab after keyword
E274tab before keyword
E275missing whitespace after keyword
E3Blank line
E301expected 1 blank line, found 0
E302expected 2 blank lines, found 0
E303too many blank lines (3)
E304blank lines found after function decorator
E305expected 2 blank lines after end of function or class
E4Import
E401multiple imports on one line
E402module level import not at top of file
E5Line length
E501 (^)line too long (82 > 79 characters)
E502the backslash is redundant between brackets
E7Statement
E701multiple statements on one line (colon)
E702multiple statements on one line (semicolon)
E703statement ends with a semicolon
E704 (*)multiple statements on one line (def)
E711 (^)comparison to None should be ‘if cond is None:’
E712 (^)comparison to True should be ‘if cond is True:’ or ‘if cond:’
E713test for membership should be ‘not in’
E714test for object identity should be ‘is not’
E721 (^)do not compare types, use ‘isinstance()’
E731do not assign a lambda expression, use a def
E741do not use variables named ‘l’, ‘O’, or ‘I’
E742do not define classes named ‘l’, ‘O’, or ‘I’
E743do not define functions named ‘l’, ‘O’, or ‘I’
E9Runtime
E901SyntaxError or IndentationError
E902IOError
W1Indentation warning
W191indentation contains tabs
W2Whitespace warning
W291trailing whitespace
W292no newline at end of file
W293blank line contains whitespace
W3Blank line warning
W391blank line at end of file
W5Line break warning
W503 (*)line break occurred before a binary operator
W6Deprecation warning
W601.has_key() is deprecated, use ‘in’
W602deprecated form of raising exception
W603‘<>’ is deprecated, use ‘!=’
W604backticks are deprecated, use ‘repr()’

  • 33
    点赞
  • 97
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值