Python PEP8 printing wrapped strings without indent

巧了我就是萌 提交于 2019-12-04 01:42:56

Use automatic string concatenation + implicit line continuation:

long_string = ("Line 1 "
               "Line 2 "
               "Line 3 ")


>>> long_string
'Line 1 Line 2 Line 3 '

This works:

if __name__=='__main__':
    usage = ('%prog [options]\nWithout any options, will display 10 random '
    'users of each type.')
    parser = OptionParser(usage)

Although I'd lay it out like this:

if __name__=='__main__':
    usage = ('%prog [options]\n'
             'Without any options, will display 10 random users '
             'of each type.')
    parser = OptionParser(usage)

(So I start a new line when there's a \n in the string, as well as when I need to word wrap the source code.)

try this:

if __name__=='__main__':
    usage = '%prog [options]\nWithout any options, will display 10 random ' \
    'users of each type.'
    parser = OptionParser(usage)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!