python - 断线访问字典的正确方法

标签 python pep8

我尝试遵守 pep8 指令,因此打破以下行:

   config_data_dict['foo']['bar']['foobarfoo'] \
        ['barfoobar'] = something_else

但是,我在 ['foobarfoo'] 部分之后收到以下警告

whitespace before '[' pep8(E211)

我应该如何像上面那样正确地断行(假设我不能在 = 附近断行)?

最佳答案

括号似乎有效:

(config_data_dict['foo']['bar']['foobarfoo']
 ['barfoobar']) = something_else

这似乎也是根据 PEP8 推荐的样式:

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.

关于python - 断线访问字典的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57148916/

相关文章:

python - 错误 : Importing notebooks requires Jupyter nbconvert to be installed

python - 给出 JSONDecodeError : Expecting , 分隔符的有效 JSON

python - 使用快捷表达式而不是三元是pythonic吗?

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

python - 2 和问题 : given an unsorted list of ints, 查找两个元素的总和是否等于给定目标。如何让我的代码更 Pythonic?

python - mysqldb更新报错typeerror 'str' object is not callable

python - 为什么 Django 会引发 "KeyError"?

python - Celery并发设置: CELERYD_CONCURRENCY and CELERYD_PREFETCH_MULTIPLIER

python 样式指南 pep 8。多行多列字典

Python 和类属性声明