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

Michele Simionato mis6 at pitt.edu
Tue Feb 11 11:19:27 EST 2003


Andrew Koenig <ark at research.att.com> wrote in message news:<yu99el6frd6j.fsf at europa.research.att.com>...
> Michele> Moreover I fear abuses like
> 
> Michele> files=[f for f in os.listdir(mydir) \
> Michele>        if (if issource: f.endswith('.py') else: True)]
> 
> Michele> to retrieve all the files or only the source files (this is a
> Michele> real case life where I would like to use the ternary
> Michele> operator, but NOT in this form!)
> 
> I don't see this is a case for the ternary operator at all.  Surely it
> is better to write
> 
>          files=[f for f in os.listdir(mydir) \
>                 if not issource or f.endswith('.py')]

I was saying I fear *abuses*. Of course, there is always the possibility
for abuses, but Python should try to avoid them as much as possible.

Moreover,

(if C: x 
else: y)

it too similar to a statement. How is it possible for a simple
parenthesis have such a strong effect ? And if this is approved,
why not

(try: x except: y) ?

I would like to keep the distinction between statement and expressions.

I am for a new keyword or psuedokeyword. I would be okay with
"when(C,x,y)" or "C then x else y" or "x when C else y" , or similar.

I dislike proposals that look like statements.




More information about the Python-list mailing list