Are line continuations needed?
Duncan Booth
me at privacy.net
Fri Apr 9 04:42:01 EDT 2004
Josiah Carlson <jcarlson at uci.edu> wrote in
news:c55811$4be$1 at news.service.uci.edu:
> Graham Breed wrote:
>
>>> 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.
>>
>>
>> mystring = """
>> +---------------+
>> | '" |
>> +---------------+
>> """[1:]
>>
>
> What about Windows? You'd need to use [2:].
No, [1:] will work fine for windows. Windows stores files on disc with
'\r\n' as line terminators, but Python (and most other programming
languages) use '\n' internally as the line terminator.
>
> I would also say that the trailing string slice is ugly.
>
Agreed. Also it wouldn't work if you wanted the string as a docstring.
More information about the Python-list
mailing list