【问题标题】:PEP8 E203 error occurs in list slice列表切片中出现 PEP8 E203 错误
【发布时间】:2018-02-05 14:15:18
【问题描述】:
buffer[start_index : start_index + nbytes]
path[1 + path.rfind('#') :]

在这种情况下,pep8库出现错误

但是,在 PEP8 文档中 (https://www.python.org/dev/peps/pep-0008/#other-recommendations)

是的:

> ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]

> ham[lower:upper], ham[lower:upper:], ham[lower::step] ham[lower+offset:upper+offset]
> ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
> ham[lower + offset : upper + offset]

没有:

> ham[lower + offset:upper + offset] ham[1: 9], ham[1 :9], ham[1:9 :3]
> ham[lower : : upper] ham[ : upper]

我觉得上面的代码没问题,但是不知道是什么问题。

【问题讨论】:

  • 我认为如果去掉冒号,就违反了“ham[lower + offset:upper + offset]”
  • 对不起删除空格而不是冒号,buffer[start_index:start_index + nbytes],以防违反ham[lower + offset:upper + offset]

标签: python pep8 autopep8


【解决方案1】:

pep8 实用程序将E203 定义为“列表切片上冒号前的空格”。

这是一种风格而不是语法错误(ie,代码将按预期工作,但风格违反 PEP8 标准):如您所见,PEP8 建议排除了周围的空格切片中使用的冒号。要删除错误,请将第一行重写为

buffer[start_index:start_index + nbytes]

pep8 也可能会或可能不会抱怨 + 运算符周围的空格,我不记得对此的建议。

【讨论】:

    猜你喜欢
    • 2013-01-21
    • 1970-01-01
    • 1970-01-01
    • 2019-04-30
    • 2017-05-16
    • 2023-03-15
    • 1970-01-01
    • 2010-12-14
    • 1970-01-01
    相关资源
    最近更新 更多