Line continuation for a string > 79 characters

Paul Brian paul1brian at yahoo.com
Wed Jan 9 11:10:41 EST 2002


Berthold,

thank you, but my main aim was to make it quick and easy for me to cut and
paste long file names in and out of scripts (I know I know, but I am doing a
lot of quick and dirty exploration)

So dividing up into '/somefile' and '/someotherfile' is more work than just
having messy files
I like the / v \\ idea - I'll try it.

Overall I think I am stuck with the \ added onto the end of my lines. Oh
well.

cheers

Paul Brian

Berthold Höllmann <hoel at germanlloyd.org> wrote in message
news:seg05fwzwz.fsf at germanlloyd.org...
"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