Break lines?

S

saneman

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

Tim Chase

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
 
S

saneman

Tim said:
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 ' ?
 
T

Tim Chase

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
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top