For review: PEP 308 - If-then-else expression

Erik Max Francis max at alcyone.com
Mon Feb 10 23:01:24 EST 2003


Michele Simionato wrote:

> I don't want to overload "if" since the typical situations where I
> would
> like to use the ternary operator, are in nested "if" expressions or in
> listcomp with "if". Having a new keyword like "when" would help
> clarity.
> Moreover I fear abuses like
> 
> files=[f for f in os.listdir(mydir) \
>        if (if issource: f.endswith('.py') else: True)]

That's just the use of a conditional operator as the conditional in an
if statement.  That's bad style in any language; Python is not an
exception.

Will there be abuses?  I'm sure there will, but that's true for every
language syntax; _any_ syntax can be abused, even in a language as
straightforward and simple as Python.  Will it give more expressivity to
those who want the syntax and know and when how to use it properly?  The
point is:  Yes.

People are already using broken, unreadable mimics _incorrectly_.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Ride / Ride this wave of mine
\__/ Res
    Esperanto reference / http://www.alcyone.com/max/lang/esperanto/
 An Esperanto reference for English speakers.




More information about the Python-list mailing list