Python PEP8:为了视觉缩进而过度缩进的续行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21947121/
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
PEP8: continuation line over-indented for visual indent
提问by Sc4r
I have this line of code which goes over the line and when testing for pep8 errors I get: line too long. So to try and fix this I used slash('\') but then I get continuation line over-indented for visual indent. What can I do to fix this?
我有这行代码,当测试pep8错误时,我得到:行太长了。因此,为了尝试解决此问题,我使用了斜杠('\'),但随后我将连续行过度缩进以进行视觉缩进。我能做些什么来解决这个问题?


Things I've tried:
我尝试过的事情:
if first_index < 0 or second_index > \
self._number_of_plates - 1:
raise ValueError
continuation line over-indented for visual indent
if first_index < 0 \
or second_index > \
self._number_of_plates - 1:
raise ValueError
continuation line over-indented for visual indent
if first_index < 0 or \
second_index > self._number_of_plates - 1:
raise ValueError
continuation line over-indented for visual indent
if first_index \
< 0 or second_index \
> self._number_of_plates - 1:
raise ValueError
continuation line over-indented for visual indent
采纳答案by David Ehrmann
The line-extending backslash has the issue of having trailing whitespace that can break your code. This is a popular fix and is PEP8-compliant:
行扩展反斜杠的问题是尾随空格可能会破坏您的代码。这是一个流行的修复程序并且符合 PEP8:
if (first_index < 0 or
second_index > self._number_of_plates - 1):

