gpt4 book ai didi

python - 在 Python 中用长类/属性名称换行

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

我想将以下几行换行以符合 PEP,我相信它们都是有效的。我听说有些人根本不推荐反斜杠,哪个对你来说不那么难看?

1

    bake_occ_static_pass.compute_behavior = (
bake_occ_static_pass.original_compute_behavior)

2

    bake_areas_animated_pass.compute_behavior = \
bake_areas_animated_pass.original_compute_behavior

提前致谢。

最佳答案

根据 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.

只有在使用括号会导致语法问题或非常奇怪的换行点(例如 withassert 语句)时才适合使用反斜杠。例如

with something('foo') as some_name, \
something_else('bar') as some_other_name:

应该优先于:

with something('foo'
) as some_name, something_else(
'bar') as some_other_name:

关于python - 在 Python 中用长类/属性名称换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25145049/

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