Is it possible to break a string literal into multiple lines?

MRAB python at mrabarnett.plus.com
Sat Nov 13 20:08:36 CET 2010


On 13/11/2010 18:53, Zeynel wrote:
> I have string formatting line in Google App Engine webframe webapp:
>
> self.response.out.write("<b>%s</b>:<br />  mWEIGHT: %s<br />
> mDATE0_integer: %s<br />  mCOUNT: %s<br />" % (result.mUNIQUE,
> result.mWEIGHT, mDATE0_integer, result.mCOUNT,))
>
> I would like to be able to write it as
>
> self.response.out.write("<b>%s</b>:<br />
>                                    mWEIGHT: %s<br />
>                                    mDATE0_integer: %s<br />
>                                   mCOUNT: %s<br />"
>                                                              %
> (result.mUNIQUE,
>
> result.mWEIGHT,
>
> mDATE0_integer,
>
> result.mCOUNT,))
>
> But neither \ or enclosing the string in parens let me break the
> string literal enclosed in "" Is this possible?

Use triple-quoted strings:

self.response.out.write("""<b>%s</b>:<br />
                                     mWEIGHT: %s<br />
                                     mDATE0_integer: %s<br />
                                    mCOUNT: %s<br />"""

(result.mUNIQUE,

result.mWEIGHT,

mDATE0_integer,

result.mCOUNT,))



More information about the Python-list mailing list