Python syntax wart

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Sun Sep 9 06:04:52 EDT 2007


Lawrence D'Oliveiro wrote:

> Not possible:
> 
>     for \
>         Link \
>     in \
>         GetEachRecord \
>           (
>             "links",
>             ("from_episode",),
>             "to_episode = %s",
>             [EpisodeID],
>             "order by when_created"
>           ) \
>     :
>         out.write \
>           (
>                 "<P><A HREF=\"%s\">Back to episode %d</A>\n"
>             %
>                 (
>                     LinkToMe({"ep" : Link["from_episode"]}),
>                     Link["from_episode"]
>                 )
>           )
>     #end for

IMHO, that's no Python syntax wart, but a coding style wart.

What's wrong with this:

for Link in GetEachRecord(
        "links",
        ("from_episode",),
        "to_episode = %s",
        [EpisodeID],
        "order by when_created"
         ):
    out.write("<P><A HREF=\"%s\">Back to episode %d</A>\n" % (
                LinkToMe({"ep" : Link["from_episode"]}),
                Link["from_episode"]
                )
            )

It's still quite crammed; I think I'd write it more explicit.

(Personally, I've never needed the possibility to tear a "for" apart
so it covers more than ten lines, or to waste lines by placing
single parentheses or colons in them -- my screen really isn't
unlimited in size.)

Regards,


Björn


-- 
BOFH excuse #247:

Due to Federal Budget problems we have been forced to cut back on
the number of users able to access the system at one time. (namely
none allowed....)




More information about the Python-list mailing list