For review: PEP 308 - If-then-else expression
Michele Simionato
mis6 at pitt.edu
Mon Feb 10 16:55:11 EST 2003
"James J. Besemer" <jb at cascade-sys.com> wrote in message news:<mailman.1044786693.18919.python-list at python.org>...
> Michele Simionato wrote:
>
> > It is EXACTLY because "if" is already overloaded that I don't want to
> > overload it even more!
>
> I think you and others exagerate the cost/danger of overloading "if".
>
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)]
to retrieve all the files or only the source files (this is a real
case life where I would like to use the ternary operator, but NOT
in this form!)
Michele
More information about the Python-list
mailing list