Allowing comments after the line continuation backslash
Ulrich Eckhardt
eckhardt at satorlaser.com
Mon Nov 1 03:50:36 EDT 2010
Yingjie Lan wrote:
> I would like to have comments after the line continuation backslash.
>
>>>> if a > 0 \ #comments for this condition
> and b > 0:
> #do something here
Historically, and also in Python, the backslash escapes the immediately
following character. That means that _nothing_ may follow the backslash and
that the backslash is not a "line continuation backslash" per se.
Now, there are ways around this, just add parens:
if (a > 0
and b > 0):
Note that this also applies to (), [] and {} when forming tuples, lists and
dicts, which you can spread across different lines.
> This is currently not OK, but this might be a good thing to have.
I'd actually argue that even the currently used backslash is a bad idea to
have.
Uli
--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
More information about the Python-list
mailing list