Python 什么是 PEP8 的 E128:为了视觉缩进而缩进不足的续行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15435811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is PEP8's E128: continuation line under-indented for visual indent?
提问by Oli
Just opened a file with Sublime Text (with Sublime Linter) and noticed a PEP8 formatting error that I'd never seen before. Here's the text:
刚刚使用 Sublime Text(使用 Sublime Linter)打开了一个文件,并注意到了一个我以前从未见过的 PEP8 格式错误。下面是正文:
urlpatterns = patterns('',
url(r'^$', listing, name='investment-listing'),
)
It's flagging the second argument, the line that starts url(...)
它正在标记第二个参数,即开始的行 url(...)
I was about to disable this check in ST2 but I'd like to know what I'm doing wrongbefore I ignore it. You never know, if it seems important I might even change my ways :)
我正准备在 ST2 中禁用此检查,但在忽略它之前我想知道我做错了什么。你永远不知道,如果这看起来很重要,我什至可能会改变我的方式:)
采纳答案by Gareth Latty
PEP-8 recommendsyou indent lines to the opening parentheses if you put anything on the first line, so it should either be indenting to the opening bracket:
PEP-8 建议您在第一行放置任何内容时将行缩进到左括号,因此它应该缩进到左括号:
urlpatterns = patterns('',
url(r'^$', listing, name='investment-listing'))
or not putting any arguments on the starting line, then indenting to a uniform level:
或者不在起跑线上放置任何参数,然后缩进到统一级别:
urlpatterns = patterns(
'',
url(r'^$', listing, name='investment-listing'),
)
urlpatterns = patterns(
'', url(r'^$', listing, name='investment-listing'))
I suggest taking a read through PEP-8 - you can skim through a lot of it, and it's pretty easy to understand, unlike some of the more technical PEPs.
我建议通读 PEP-8 - 你可以浏览很多,而且它很容易理解,不像一些技术性更强的 PEP。
回答by displayname
This goes also for statements like this (auto-formatted by PyCharm):
这也适用于这样的语句(由 PyCharm 自动格式化):
return combine_sample_generators(sample_generators['train']), \
combine_sample_generators(sample_generators['dev']), \
combine_sample_generators(sample_generators['test'])
Which will give the same style-warning. In order to get rid of it I had to rewrite it to:
这将给出相同的风格警告。为了摆脱它,我不得不将其重写为:
return \
combine_sample_generators(sample_generators['train']), \
combine_sample_generators(sample_generators['dev']), \
combine_sample_generators(sample_generators['test'])

