gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:23:01 25 4
gpt4 key购买 nike

我的代码:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com