python - 提出了 PEP 8 E211 问题。不知道为什么

标签 python

我的代码:

if 'certainField' in myData['meta']['loc']:
   something = myData['meta'] \            <- PEP8 E11 raised for this
   ['loc'] \                               <- PEP8 E11 raised for this
   ['certainField'] \                      <- PEP8 E11 raised for this
   ['thefield']

代码按预期工作。但是 PEP 8 E211 是为第二、第三和第四行提出的,声称 '[' 之前的空格

我不明白。我如何格式化才能满足 PEP 8?

最佳答案

您可以将您的语句包裹在括号中并删除 \

if 'certainField' in myData['meta']['loc']:
    something = (myData['meta']
                 ['loc']
                 ['certainField']
                 ['thefield'])


这是一个摘录表格 PEP 8关于包装长行:

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.

Backslashes may still be appropriate at times. For example, long, multiple with -statements cannot use implicit continuation, so backslashes are acceptable:

关于python - 提出了 PEP 8 E211 问题。不知道为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39071967/

相关文章:

python - 我如何测试我的 Tic Tac Toe A.I.是完美的?

python - 使用 Paramiko 一次创建多个 SSH 连接

python - pip install 自定义包含路径

python - 计算 2 个 numpy 数组的百分比值

python - 是什么导致 numpy.nanstd() 返回 nan?

python - 在 matplotlib basemap 正射投影中更改图像背景颜色

python - 如何在终端中重写输出

Python, pygame 无法打开 chic.jpg

python - 为什么在具有相同硬件的不同计算机上读取sqlite数据库速度较慢?

python - matplotlib - 如何使用 MaxNLocator 并指定必须位于 Axis 中的数字?