Python syntax wart

Stefan Behnel stefan.behnel-n05pAM at web.de
Sun Sep 9 08:20:39 CEST 2007


Marc 'BlackJack' Rintsch wrote:
> On Sun, 09 Sep 2007 17:16:05 +1200, 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:
>>
>> […]
>>
>> 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
> 
> What do you mean by not possible!?  This compiles fine for me.

He means he has to use backslashes instead of parentheses here.

Which is not true, you could easily rephrase this as:

    for link in GetEachRecord(
             "links",
             ....):
        out.write(
             ....
             )

See? No backslash!

Stefan



More information about the Python-list mailing list