stretching a string over several lines (Re: PyChecker messages)

Steven Bethard steven.bethard at gmail.com
Tue Jan 11 08:45:01 CET 2005


Frans Englich wrote:
> Also, another newbie question: How does one make a string stretch over several 
> lines in the source code? Is this the proper way?

(1)
> print "asda asda asda asda asda asda " \
> 	"asda asda asda asda asda asda " \
> 	"asda asda asda asda asda asda"

A couple of other options here:

(2)
print """asda asda asda asda asda asda
asda asda asda asda asda asda
asda asda asda asda asda asda"""

(3)
print """\
asda asda asda asda asda asda
asda asda asda asda asda asda
asda asda asda asda asda asda"""

(4)
print ("asda asda asda asda asda asda "
        "asda asda asda asda asda asda "
        "asda asda asda asda asda asda")

Note that backslash continuations (1) are on Guido's list of "Python 
Regrets", so it's likely they'll disappear with Python 3.0 (Of course 
this is 3-5 years off.)

I typically use either (3) or (4), but of course the final choice is up 
to you.

Steve



More information about the Python-list mailing list