<分区>
我发现自己经常断弦只是为了让它们在下一行。当然,当我去更改这些字符串时(想想记录消息),我必须重新格式化中断以将它们保持在 80 列内。
大多数人如何处理这个问题?
标签 python
<分区>
我发现自己经常断弦只是为了让它们在下一行。当然,当我去更改这些字符串时(想想记录消息),我必须重新格式化中断以将它们保持在 80 列内。
大多数人如何处理这个问题?
最佳答案
我建议尽量坚持 80 列,但不要任何代价。有时,就像记录消息一样,让它们保持长久比分手更有意义。但对于大多数情况,如复杂条件或列表理解,分解是一个好主意,因为它会帮助您将复杂的逻辑划分为更容易理解的部分。更容易理解:
print sum(n for n in xrange(1000000)
if palindromic(n, bits_of_n) and palindromic(n, digits))
比:
print sum(n for n in xrange(1000000) if palindromic(n, bits_of_n) and palindromic(n, digits))
如果你刚写的,你可能看起来是一样的,但几天后那些长行就变得难以理解了。
最后,虽然 PEP 8 规定了列限制,但它还说:
A style guide is about consistency. Consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is most important.
But most importantly: know when to be inconsistent -- sometimes the style guide just doesn't apply. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don't hesitate to ask!
关于python - 你是否很难用 Python 保持 80 列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/583048/
相关文章:
python - 按数据框中的一列进行分组,但将其中一些组汇总为一组
python - 从调用的 Python 代码返回 UiPath Studio 序列的参数
python - 多 View 特征点的OpenCV Flann匹配
python - SPI_SETSCREENSAVETIMEOUT 不适用于使用 Python 和 ctypes 的 Windows 7
python - 如果多列中的任何一列在 Pandas 中有重复的行,则删除行
python - 如何使用 F-score 作为误差函数来训练神经网络?
python - 属性错误 : module 'jinja2.ext' has no attribute 'autoescape' while trying to use Flask-Babel