[Python-ideas] (try-except) conditional expression similar to (if-else) conditional (PEP 308)

Nick Coghlan ncoghlan at gmail.com
Thu Aug 6 14:29:31 CEST 2009


(moving to python-ideas where this thread belongs)

ilya wrote:
> and I think this can be done just as easily with existing syntax:
> 
>     x = try_1(float, string, except_ = float('nan'), if_ = ValueError)
>     y = try_2(float, string, { ValueError: float('nan') })

As with PEP 308, the thing missing from function based solutions is lazy
evaluation of the operands. They also tend be seriously ugly, as is the
case with the above suggestions.

Given Guido's reluctance in adding the far more common conditional
expressions, I suspect this idea isn't ever going to get anywhere, but
even if that is the case it might be nice to have a rejected PEP that
makes this explicit.

If we were going to do it, I would definitely favour the "EXPR except
ALT_EXPR if EXCEPTION" format, but I doubt it is actually going to get
that far.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------



More information about the Python-ideas mailing list