Python syntax wart

Carl Banks pavlovevidence at gmail.com
Sun Sep 9 04:16:58 EDT 2007


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:
> 
>     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"
>           ) \
>     :

Hmm.  Complaints about the backslash come up from time to time, but this 
is the first time I can recall anyone complaining because you couldn't 
break a line right after the "for" keyword.

I'm sure you'll find agreement that backslash continuations are ugly, but 
probably hardly anyone feels compelled to use them the way you 
demonstrate above.


[snippage]

>     #end for

No offense, but using things like "#end for" isn't really the best way to 
impress (most of) the Python community with your eye for syntax.

You're relatively new to Python, correct?  If so, maybe you should give 
yourself some time to see if some of Python's unconventional features 
grow on you.  I've found that wherever Python differs from the common 
ways to do things, it's usually different in a good way.  You should give 
Python a chance to be Python, without trying to force it to be like 
languages that do things like break for statements into several lines, or 
use block delimiters.


Carl Banks



More information about the Python-list mailing list