python - PEP8 : continuation line over-indented for visual indent

标签 python

我有这行代码,在测试 pep8 错误时我得到: 线太长。因此,为了尝试解决此问题,我使用了 slash('\') 但随后我将延续行过度缩进以进行视觉缩进。我该怎么做才能解决这个问题?

enter image description here

我尝试过的事情:

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

最佳答案

行扩展反斜杠的问题是尾随空格会破坏您的代码。这是一种流行的修复方法,并且符合 PEP8:

if (first_index < 0 or
    second_index > self._number_of_plates - 1):

关于python - PEP8 : continuation line over-indented for visual indent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21947121/

相关文章:

python - AppEngine 数据策略来处理每个用户的大索引?

python - Django CreateView - 仅显示外键字段中的特定对象

python - 并行重新分配大型数组中的元素

python - 从文本文件复制并将编号的行写入另一个文件

python - 使用循环将 CSV 数据提取到对象中

python - 如何在 Django 模板的结果页面中突出显示搜索到的查询?

python - 在 numpy 数组中前向填充 NaN 值的最有效方法

python - 格式化为整数的 numpy savetxt 不保存零

python - 使用复杂的列表数据编写 CSV 文件

python - 在 spaCy 中包含词典(地名词典)以改进 NER 的理想方法是什么?