在尝试遵守python样式规则时,我将编辑器设置为最多79列。
在PEP中,它建议在括号,括号和括号内使用python隐含的延续。 但是,当我达到col限制时处理字符串时,它会有点奇怪。
例如,尝试使用多行
mystr = """Why, hello there
wonderful stackoverflow people!"""
将返回
"Why, hello there\nwonderful stackoverflow people!"
这有效:
mystr = "Why, hello there \
wonderful stackoverflow people!"
因为它返回:
"Why, hello there wonderful stackoverflow people!"
但是,当语句缩进几个块时,这看起来很奇怪:
do stuff:
and more stuff:
and even some more stuff:
mystr = "Why, hello there \
wonderful stackoverflow people!"
如果您尝试缩进第二行:
do stuff:
and more stuff:
and even some more stuff:
mystr = "Why, hello there \
wonderful stackoverflow people!"
你的字符串最终为:
"Why, hello there wonderful stackoverflow people!"
我发现解决这个问题的唯一方法是:
do stuff:
and more stuff:
and even some more stuff:
mystr = "Why, hello there" \
"wonderful stackoverflow people!"
我觉得哪个更好,但眼睛也有些不安,因为看起来有一根绳子只是坐在不知名的地方。 这将产生适当的:
"Why, hello there wonderful stackoverflow people!"
所以,我的问题是 - 关于如何做到这一点的一些人的建议是什么?在样式指南中是否有我缺少的东西,它确实显示了我应该如何做到这一点?
谢谢。