Hot to split string literals that will across two or more lines ?
aleax at mail.comcast.net
Fri Nov 18 06:25:44 CET 2005
Ben Finney <bignose+hates-spam at benfinney.id.au> wrote:
> Tony Nelson <*firstname*nlsnews at georgea*lastname*.com> wrote:
> > While we're at it, I use bracketing instead of line continuation:
> > print ( "a long string, longer than this "
> > "and some more of the string" )
> To continue the pedantry: Those are parentheses, not brackets.
> Slightly more on-topic, the parentheses make it look like a sequence
> to this reader (though, without a comma, not to the Python parser, of
Nevertheless, my favorite style has also always been to use parentheses,
and I was glad to see, on joining Google and studying its in-house
Python style guide, that Google mandates that style, too. After all,
though they're overloaded, it's _commas_ that make a tuple, not
parentheses, which essentially just *group* things (in cases where the
language's syntax would otherwise not suit you). So, you always do have
to watch out for commas, ayway, since, e.g.,
x = "Sempre caro", "mi fu"
x = "Sempre caro mi fu"
are so different -- it makes no difference whether either or both of
these assigments use parentheses (after the = and at line end), it's the
comma that does make all the difference. So, you can see it as a very
good side effect of the "long string use parentheses, not backslashes"
style rule, that the reader is soon weaned of the mistake of believing
that parentheses signify tuples.
More information about the Python-list