当变量嵌套好几级、名称相当长并且被分配相当长的值/表达式时,为变量分配值的首选样式是什么。
例如:
if this:
if that:
if here:
if there:
big_variable['big_key']['big_value'] = another_big_variable_that_pushes_line_over_79_characters
other_thing = something
字符限制违规只是个位数,但我想清理我的代码,以便它尽可能忠实地遵循 PEP 8。我已经完成了以下操作,但我对 python 还是很陌生,我不确定这是否会让经验丰富的 python 程序员畏缩:
if this:
if that:
if here:
if there:
big_variable['big_key']['big_value'] = \
another_big_variable_that_pushes_line_over_79_characters
other_thing = something
我的印象是续行字符有些禁忌;但是如果我正在使用这些大字典并且我无法在变量名的中间进行彻底的休息,我真的想不出比我拥有的更清洁的解决方案。