Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Break lines?

Reply
Thread Tools

Break lines?

 
 
saneman
Guest
Posts: n/a
 
      02-26-2008
I have made this string:


TITLE = 'Efficiency of set operations: sort model,
(cphstl::set::insert(p,e)^n cphstl::set::insert(e)), integer'

But I am not allowed to break the line like that:

IndentationError: unexpected indent

How do I break a line?
 
Reply With Quote
 
 
 
 
Tim Chase
Guest
Posts: n/a
 
      02-26-2008
> I have made this string:
>
> TITLE = 'Efficiency of set operations: sort model,
> (cphstl::set::insert(p,e)^n cphstl::set::insert(e)), integer'
>
> But I am not allowed to break the line like that:
>
> IndentationError: unexpected indent
>
> How do I break a line?


Depends on what you want. You can embed running strings with
newlines using triple-quotes (either single- or double-quotes):

TITLE = """Efficiency...
(cphstl:..."""


Or you can use string concatenation using line-continuations:

TITLE = "Efficiency..." \
"(cphstl:..."

or using parens

TITLE = ("Efficiency..."
"(cphstl:...")



I like the clean'ness of the first version, but sometimes get
irked by it including my leading whitespace (there are some
workarounds, but all involve more than trivial effort). I tend
to use the 2nd in the case you describe, but usually using the
3rd version in all other cases where it's as a parameter to a
function call or some other bracketed/braced construct.

-tkc


 
Reply With Quote
 
 
 
 
saneman
Guest
Posts: n/a
 
      02-26-2008
Tim Chase wrote:
>> I have made this string:
>>
>> TITLE = 'Efficiency of set operations: sort model,
>> (cphstl::set::insert(p,e)^n cphstl::set::insert(e)), integer'
>>
>> But I am not allowed to break the line like that:
>>
>> IndentationError: unexpected indent
>>
>> How do I break a line?

>
> Depends on what you want. You can embed running strings with newlines
> using triple-quotes (either single- or double-quotes):
>
> TITLE = """Efficiency...
> (cphstl:..."""
>
>
> Or you can use string concatenation using line-continuations:
>
> TITLE = "Efficiency..." \
> "(cphstl:..."
>
> or using parens
>
> TITLE = ("Efficiency..."
> "(cphstl:...")
>
>
>
> I like the clean'ness of the first version, but sometimes get irked by
> it including my leading whitespace (there are some workarounds, but all
> involve more than trivial effort). I tend to use the 2nd in the case
> you describe, but usually using the 3rd version in all other cases where
> it's as a parameter to a function call or some other bracketed/braced
> construct.
>
> -tkc
>
>


Ok thanks! Btw why double quotes " instead of single ' ?
 
Reply With Quote
 
Tim Chase
Guest
Posts: n/a
 
      02-26-2008
> Ok thanks! Btw why double quotes " instead of single ' ?

Either one will do...there's not much difference. I try to use
double-quotes most of the time, just so when I include an
apostrophe in-line (which I do more often than I include a
double-quote in-line), I don't have to think.

string1a = "John's dog"
string1b = 'John\'s dog'
string2a = "She said \"hello\""
string2b = 'She said "hello"'
string3a = 'She said "John\'s nice" in a letter'
string3b = "She said \"John's nice\" in a letter'
string3c = """She said "John's nice" in a letter"""
string3d = '''She said "John's nice" in a letter'''

My usual aim is for clarity, so I tend to go with the versions
that have the fewest backslashes in them.

-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
`if (!p ? i++ : 0) break;' == `if (!p){ i++; break;}' ? lovecreatesbea...@gmail.com C Programming 12 04-14-2008 07:59 AM
break Wifi ? miro Wireless Networking 1 02-18-2005 12:44 AM
Perl loops should use break, not last Jeremy Morton Perl 1 01-30-2005 10:50 PM
Did today's Windows updates break wireless?? The Celtic Warrior Wireless Networking 2 07-15-2004 10:41 PM
Word wrap line break code and algorithm for c# Jason Coyne Gaijin42 ASP .Net 0 04-08-2004 07:26 PM



Advertisments