Allowing comments after the line continuation backslash
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Tue Nov 2 07:22:19 EDT 2010
On Tue, 02 Nov 2010 11:16:46 +1300, Lawrence D'Oliveiro wrote:
> In message <4CCE6FF6.2050408 at v.loewis.de>, Martin v. Loewis wrote:
>
>> (in fact, I can't think any situation where I would use the backslash).
>
> for \
> Description, Attr, ColorList \
> in \
> (
> ("normal", "image", MainWindow.ColorsNormalList),
> ("highlighted", "highlight",
> MainWindow.ColorsHighlightedList), ("selected", "select",
> MainWindow.ColorsSelectedList),
> ) \
> :
> ...
> #end for
If it were your intention to show why backslashes should be avoided, you
succeeded admirably.
The above can be written much more cleanly as:
for Description, Attr, ColorList in (
("normal", "image", MainWindow.ColorsNormalList),
("highlighted", "highlight", MainWindow.ColorsHighlightedList),
("selected", "select", MainWindow.ColorsSelectedList),
):
pass
with no backslashes required. An even better way would be to given the
tuples descriptive names, so that anyone maintaining this software can
easily see what they are for:
# States should be tuples (description, attribute name, colour list).
standard = ("normal", "image", MainWindow.ColorsNormalList)
highlighted = ("highlighted", "highlight",
MainWindow.ColorsHighlightedList)
selected = ("selected", "select", MainWindow.ColorsSelectedList)
for desc, attr, color_list in (standard, highlighted, selected):
pass
--
Steven
More information about the Python-list
mailing list