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

Zeynel azeynel1 at gmail.com
Sat Nov 13 14:35:48 EST 2010


Tim Chase and MRAB: Thanks!!

On Nov 13, 2:14 pm, Tim Chase <python.l... at tim.thechases.com> wrote:
> On 11/13/2010 12:53 PM, 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 python's triple-quoted strings:
>
>    self.response.out.write("""<b>%s</b>:<br />
>         mWEIGHT: %s ...
>         ... <br />""")
>
> Or alternatively, you can do something like
>
>    self.response.out.write(
>      "<b>%s</b>:br />"
>      "mWEIGHT: %s ..."
>      ...
>      "...<br />"
>      )
>
> (that excludes newlines and leading whitespace in the string that
> gets written, but you can modify the string contents to include
> them if you need/want)
>
> -tkc




More information about the Python-list mailing list