Allowing comments after the line continuation backslash

Mark Wooding mdw at distorted.org.uk
Sun Nov 7 08:41:27 EST 2010


Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> writes:

> Not surprising, since the above list has become completely divorced from its 
> original purpose. Anybody remember what that was? It was supposed to be used 
> in a loop, as follows:
>
>     for \
>         Description, Attr, ColorList \
>     in \
>         (
>             ("normal", "image", MainWindow.ColorsNormalList),
>             ("highlighted", "highlight", MainWindow.ColorsHighlightedList),
>             ("selected", "select", MainWindow.ColorsSelectedList),
>         ) \
>     :
>        ...
>     #end for
>
> Does this make more sense now?

Ugh, no!

for descr, attr, colours in [
        ('normal',      'image',        'Normal'),
        ('highlighted', 'highlight',    'Highlighted'),
        ('selected',    'select',       'Selected')]:
  colourlist = getattr(MainWindow, 'Colors%sList' % colours)
  ## ...

To be honest, there's so much regularity in that table that I'd consider
generating it from a shorter list.  This would obviously involve
refactoring something else to eliminate the image/normal asymmetry.  I'd
also consider making the ColorsMumbleList attribute collection into a
dictionary.

Note that my columns are aligned to 8-column tab stops for easy
maintenance (although my editor has used physical spaces rather than
tabs).

-- [mdw]



More information about the Python-list mailing list