python - 无法通过不合逻辑的行 pep8 错误

标签 python if-statement pep8

我已经尝试解决这个问题一段时间了,但我就是无法让它通过 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

知道它有什么问题吗?这些行与第一个括号缩进,所以我真的不知道。

最佳答案

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')

关于python - 无法通过不合逻辑的行 pep8 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22521608/

相关文章:

python - 在某些情况下,pep8 是否无法识别 `# noqa`?

python - pep8 仅注册 "ignore"参数中的第一个值

python - 用圆逼近多边形

python - 在 RQ 中排队实例方法或对象?

c# - 为什么这个方法,我认为是更快的,更慢的?

python - Sublime Text 自动缩进 Python 关键字参数

python - Keras 模型训练在一段时间后会占用更多时间

python - Python 中一个数组出现在另一个数组中的次数

c++ - 基于 boolean C++ 确定值的最快方法

python - "if"语句查找剩余数字并附加到 csv 列表中