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

Michele Simionato mis6 at pitt.edu
Sat Feb 8 09:11:54 EST 2003


"Paul Paterson" <hamonlypaulpaterson at houston.rr.com> wrote in message news:<8eY0a.2044$yn1.144744 at twister.austin.rr.com>...
> "holger krekel" <pyth at devel.trillke.net> wrote in message
> news:mailman.1044640102.26759.python-list at python.org...
> >
> > It has happenend with list comprehensions before. But this doesn't
> > mean it's generally a good thing.  For example consider
> >
> >     if obj() if callable(obj) else default:
> >        ...
> 
> One of the most compelling, one-line counter arguments I've ever seen!
> 
> Paul

I think the problem is not with the ternary operator, but with the abuse
of "if". The C-like sintax

 if (callable(obj)? obj(): default):

or the more pythonic "when"

 if (when callable(obj) obj() else default):

would be less confusing. I think introducing a ternary operator is
worthwhile but one needs a new keyword to avoid confusion
with the "if" statement.




More information about the Python-list mailing list