Are line continuations needed?

Duncan Booth me at privacy.net
Thu Apr 8 04:32:02 EDT 2004


"John Roth" <newsgroups at jhrothjr.com> wrote in
news:1079015hfg56i28 at news.supernews.com: 

>> Without the backslash continuation, you're forced to write multiline
> strings
>> with the first line indented differently from the rest of the lines:
>>
>> mystring = """first line
>> second line
>> third line"""
>>
>> Yuck.
>>
>> Backslash continuation fixes this, as David showed:
>>
>> mystring = """\
>> first line
>> second line
>> third line"""
>>
>> Maybe there will be some other way to do clean multiline strings in
>> Python 3.0?
> 
> Since you aparently used tab indentation, your examples came
> through with no indentation, so I can't tell what you're talking
> about. 

I think that you might find there wasn't any indentation to lose. Read the 
point more carefully and you might see he has a valid concern. Consider 
this (none of the lines are indented):

mystring = """\
+---------------+
|    '"         |
+---------------+
"""

Without a line continuation there simply isn't any way to write this string 
and still have the box characters line up neatly.




More information about the Python-list mailing list