Haf*_*ian 3 python coding-style pep8
有人提到,Python脚本中的一行最好不要超过80个字符.例如:
print("A very long strings")
Run Code Online (Sandbox Code Playgroud)
它是否包括print函数的字符,字符串(包括空格),括号等?
它不仅限于其他功能print吗?
这背后的原因是什么?已经谷歌搜索答案,但仍然无法真正得到答案.
它包括一切.
原因是很长的线条会妨碍清晰度和可读性.
使用python代码样式指南中的示例,这对您来说更容易阅读?
with open('/path/to/some/file/you/want/to/read') as file_1, open('/path/to/some/file/being/written', 'w') as file_2:
file_2.write(file_1.read())
Run Code Online (Sandbox Code Playgroud)
要么
with open('/path/to/some/file/you/want/to/read') as file_1, \
open('/path/to/some/file/being/written', 'w') as file_2:
file_2.write(file_1.read())
Run Code Online (Sandbox Code Playgroud)
另一个原因是历史性的.我链接到上面的相同部分中的样式指南提到了各种情况下的72,79和80-100字符限制.这些是打孔卡的列长度.
| 归档时间: |
|
| 查看次数: |
1569 次 |
| 最近记录: |