Python syntax wart
James Stroud
jstroud at mbi.ucla.edu
Sun Sep 9 15:36:02 EDT 2007
Lawrence D'Oliveiro wrote:
> The one thing I don't like about Python syntax is using backslashes to
> continue lines. Yes, you can avoid them if you can include parentheses
> somehow, but this isn't always possible.
>
> Possible:
>
> if (
> quitting
> and
> len(client["to_write"]) == 0
> and
> len(client["read"]) + client["to_read"] == 0
> ) :
> close_client(client, "shutting down")
> #end if
>
> 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
>
I usually write my code in a way that can be understood by looking at
it, with self-documenting names, clear organization, and lines that fit
under 72 characters (if I can help it). But if you insist on making perl
noise, go 'head.
record_type = "links"
episodes = ("from_episode",)
format = "to_episodes = %s"
ids = [EpisodeID]
order = "order by when_created"
records = GetEachRecord(record_type, episodes, format, ids, order)
for Link in records:
template = "<P><A HREF=\"%s\">Back to episode %d</A>\n"
the_link = Link["from_episode"]
target = LinkToMe({"ep" : Link["from_episode"]})
msg = template % (target, the_link)
out.write(msg)
James
More information about the Python-list
mailing list