Line continuation for a string > 79 characters
Berthold Höllmann
hoel at germanlloyd.org
Wed Jan 9 06:02:04 EST 2002
"Paul Brian" <paul1brian at yahoo.com> writes:
> Dear all,
>
> probably a foolish question, but how do I break up a string that has more
> than 79 characters so it looks pretty / adheres to style guides?
> eg
>
> filename = '\\myroot\\somefolder...arbitrarty
> path...\\yetanotherfolder\\foo.txt'
>
> I can do this
>
> filename = '\\myroot\\somefolder\\someotherfolder\
> \\anotherfolder\\stillanotherfolder\
> \\yetanotherfolder\\foo.txt'
First using slashes instead of backsleashes saves some characters:
filename = '/myroot/somefolder/someotherfolder\
/anotherfolder/stillanotherfolder\
/yetanotherfolder/foo.txt'
and then you could write
filename = ('/myroot'
'/somefolder'
'/someotherfolder'
'/anotherfolder'
'/stillanotherfolder'
'/yetanotherfolder'
'/foo.txt')
or
import os, os.path
filename = os.sep + os.path.join('myroot',
'somefolder',
'someotherfolder',
'anotherfolder',
'stillanotherfolder',
'yetanotherfolder',
'foo.txt')
Greetings
Berthold
--
Dipl.-Ing. Berthold Höllmann __ Address:
hoel at germanlloyd.org G / \ L Germanischer Lloyd
phone: +49-40-36149-7374 -+----+- Vorsetzen 32/35 P.O.Box 111606
fax : +49-40-36149-7320 \__/ D-20459 Hamburg D-20416 Hamburg
More information about the Python-list
mailing list