为了遵守python样式规则,我将我的编辑器设置为最多79个cols。
在PEP中,它建议在方括号、圆括号和大括号中使用python的隐含延续。然而,当我遇到列限制时,当我处理字符串时,它变得有点奇怪。
例如,尝试使用多行
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!"
那么,我的问题是-一些人对如何做到这一点有什么建议,在风格指南中是否有我遗漏了什么,这说明了我应该如何做到这一点?
谢谢。
https://stackoverflow.com/questions/5437619
复制相似问题