long string constants

Oliver Fromme olli at secnetix.de
Mon Nov 12 12:27:24 EST 2001


Mikael Olofsson <mikael at isy.liu.se> wrote:
 > On 12-Nov-2001 Holger Fuessler wrote:
 > >  Now my question. Is it possible to spread very long string constants
 > >  over multiple lines?.
 > 
 > """Do you 
 > mean 
 > like this?
 > """

Additionally, if you don't want to include newlines inside
your string (opposed to what the above suggestion does),
then you can simply break the string constants into multiple
parts and use line continuation, like this:

>>> s = "%s " \
...     "%s " \
...     "%s " % \
...     ("foo",
...      "bar",
...      "baz")
>>> s
'foo bar baz '

Note that you don't have to use explicit backslashes within
the parentheses of the tuple (they wouldn't hurt, though).

Regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co KG, Oettingenstr. 2, 80538 München
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

"All that we see or seem is just a dream within a dream" (E. A. Poe)



More information about the Python-list mailing list