【发布时间】:2014-03-20 01:21:37
【问题描述】:
我已经尝试解决这个问题一段时间了,但我无法让它通过 pep8。 这是我的代码:
1.
if (len(regex) > 2 and regex[0] == '(' and regex[-1] == ')' and
sum(regex.count(char) for char in splitter) == 1 and
regex.count('(') == 1 and regex.count(')') == 1):
print('hi')
2.
if (len(regex) > 2 and regex[0] == '(' and regex[-1] == ')' and
sum(regex.count(char) for char in splitter) == 1 and
regex.count('(') == 1 and regex.count(')') == 1):
print('hi')
3.
if (len(regex) > 2 and regex[0] == '(' and regex[-1] == ')'
and regex.count('(') > 1):
print('hi')
我在 3 个 if 语句中的每一个都收到以下 PEP8 错误:
E125 continuation line does not distinguish itself from next logical line
知道它有什么问题吗?这些行与第一个括号缩进,所以我真的不知道。
【问题讨论】:
-
到底是什么问题?
-
pep8 给了我以下错误: regex_functions_draft.py:44:9: E125 续行无法与下一个逻辑行区分开来。我尝试用第一个括号正确缩进它,但它似乎不起作用。
-
@FredMitchell 正则表达式只是一个变量,并不相关。 if 语句有效,这就是 pep8 处理我缩进 if 语句的方式。
-
在 PEP8 模块的 github 页面上还有一个关于这个问题的有趣错误报告:github.com/jcrocholl/pep8/issues/126
标签: python if-statement pep8