Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Is it possible to break a string literal into multiple lines?

Reply
Thread Tools

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

 
 
Zeynel
Guest
Posts: n/a
 
      11-13-2010
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?
 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      11-13-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,))
 
Reply With Quote
 
 
 
 
Tim Chase
Guest
Posts: n/a
 
      11-13-2010
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





 
Reply With Quote
 
Zeynel
Guest
Posts: n/a
 
      11-13-2010
Tim Chase and MRAB: Thanks!!

On Nov 13, 2:14*pm, Tim Chase <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error when inserting xml into database - string literal too long nikkilou@nycap.rr.com Java 0 06-24-2006 06:03 AM
Insert a new line character into a string literal Water Cooler v2 Javascript 4 04-18-2006 12:02 PM
Insert Server Control Into HTML String (via Literal) at runtime Guadala Harry ASP .Net 14 04-27-2005 12:12 AM
What's wrong with rpc-literal? Why use doc-literal? Anonieko Ramos ASP .Net Web Services 0 09-27-2004 09:06 AM
Possible to break into programming job with MCAD? Jane MCAD 6 06-21-2004 02:54 PM



Advertisments