可能有一个简单的答案,只是不知道如何从我的搜索中挑出它。在
我在python代码中坚持使用PEP8,目前正在为我正在编写的脚本使用OptionParser。为了防止行超出带80的值,我在需要的地方使用反斜杠。在
例如:
if __name__=='__main__':
usage = '%prog [options]\nWithout any options, will display 10 random \
users of each type.'
parser = OptionParser(usage)
反斜杠后的缩进将导致:
^{pr2}$“随机”之后的间隙让我很烦。我可以做:
if __name__=='__main__':
usage = '%prog [options]\nWithout any options, will display 10 random \
users of each type.'
parser = OptionParser(usage)
但这也让我很恼火。这看起来很傻:
if __name__=='__main__':
usage = ''.join(['%prog [options]\nWithout any options, will display',
' 10 random users of each type.'])
parser = OptionParser(usage)
一定有更好的办法吗?在
这是有效的:
尽管我会这样说:
^{pr2}$(所以当字符串中有一个
\n
时,以及当我需要对源代码进行文字包装时,我会开始一个新行。)使用automatic string concatenation+implicit line continuation:
试试这个:
相关问题 更多 >
编程相关推荐