我试过了
#:PEP8 -E223
或者
# pep8: disable=E223
我本以为第二个方法可以奏效,但似乎不起作用。
你有什么想法可以解决这个问题吗?
尝试在代码行的末尾(两个空格后)添加# nopep8
。因此,如果代码行是:
h=1+2+3+4+5+6+func( "hello","world")
那么为了忽略该行上许多Pep8错误,它变成了:
然后,为了忽略该行上大量的Pep8错误,它变为:
h=1+2+3+4+5+6+func( "hello","world") # nopep8
#nopep8:E501
。 - Bilal Akil让我补充一些可能是在之前所有答案发布之后引入的内容。
如果您使用Flake8,您可以通过添加特定的注释来忽略特定行中引发的特定规则违例。
# noqa: F401
在行末,F401
这里是一个错误代码示例。有关所有违规代码的列表,请参见http://flake8.pycqa.org/en/3.5.0/user/error-codes.html 和 https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
您还可以通过添加 来忽略整个文件中的所有违规内容
# flake8: noqa
文件中的任何位置。
--ignore
标志来禁用您上面提到的错误。pep8 --ignore=E223 file_name.py
针对多个错误
pep8 --ignore=E223,E501 file_name.py
要深入了解其他标志,请扫描 http://pep8.readthedocs.org/en/latest/intro.html。
flake8-putty
绝对是最好的方法 - 因为它允许更细粒度的控制,可以禁用哪些文件的哪些内容。 - alecxe--per-file-ignores
选项来忽略整个文件中特定的警告。flake8 --per-file-ignores='project/__init__.py:F401,F403 setup.py:E121'
[flake8]
per-file-ignores =
__init__.py: F401,F403
setup.py: E121
other/*: W9
setup.cfg
)来完成这个操作:[tool:pytest]
pep8ignore =
*.py E501 W503
api.py E402 <=============== HERE
doc/* ALL
pep8maxlinelength = 120
flakes-ignore =
UnusedImport
filterwarnings =
ignore::DeprecationWarning