Are line continuations needed?

John Roth newsgroups at jhrothjr.com
Wed Apr 7 18:25:03 EDT 2004


"Michael Geary" <Mike at DeleteThis.Geary.com> wrote in message
news:1078skqn9hgdd19 at corp.supernews.com...
> John Roth wrote:
> > [Backslash line continuations are], I believe, planned for
> > removal in 3.0. Remember that 3.0 will break everything
> > anyway: it's the release for incompatible changes.
>
> If this is true, it will put Python at a disadvantage compared to Perl
with
> regard to multiline strings. I thought David Bolen's example was pretty
> compelling.
>
> 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've seen a number of ways of handling pretty-printing multi line
strings while still making them come out the way you want.

For example, as someone else mentioned, you could do this:

mystring = ("first line"
                  "second line"
                  "Third line")

The parenthesis handle the continuations, and automatic concatination
of adjacent strings take care of the rest.

Or if you want to use a multi-line string, then you could split it on
whitespace and then join it again with a single space separator.

There are a number of other things you can do, and some of them
would be rather difficult to support syntactical.

John Roth
>
> -Mike
>
>





More information about the Python-list mailing list