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

Z

Zeynel

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?
 
M

MRAB

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,))
 
T

Tim Chase

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
 
Z

Zeynel

Tim Chase and MRAB: Thanks!!

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top