Python、PEP-8、E122 续行缺少缩进或缩进

标签 python pep8

我收到此错误,但无论我选择缩进它,我仍然收到它,您知道为什么吗?

if len(argmaxcomp) == 1:
    print "The complex with the greatest mean abundance is: {0}"\
    .format(argmaxcomp[0])

最佳答案

通常 pep8 建议你 prefer parenthesis over continuation lines .

The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.

即:

if len(argmaxcomp) == 1:
    print("The complex with the greatest mean abundance is: {0}"
          .format(argmaxcomp[0]))

另一种选择是使用 python 3 的打印:

from __future__ import print_function

if len(argmaxcomp) == 1:
    print("The complex with the greatest mean abundance is:", argmaxcomp[0])

注意:print_function 可能会中断/需要更新其余代码...在您使用过 print 的任何地方。

关于Python、PEP-8、E122 续行缺少缩进或缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33147599/

相关文章:

python - 打印单引号在 .txt 文件中变成奇怪的字符

python - 在字典中存储逻辑条件并将它们传递给 if 语句

python - 在 iPython 笔记本代码中验证 PEP8

python - 如何在 PyCharm 中为 flake8 启用自动代码格式化

python - 如果我不需要函数返回的变量,如何满足 PEP8 中的未使用变量规则?

python - ST3 中的 Linter "line too long"错误和多行字符串内空格过多

python - rawpy.Params中output_bps的含义

python - 使用 python 或 ironpython 访问 mssql 的最简单方法是什么?

python - WordPress Api 请求错误 : [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl. c:700)

python - 测试类的 PEP8 命名约定