[Python-ideas] exception based conditional expression, similar to if-else conditional expression

Nick Coghlan ncoghlan at gmail.com
Fri Aug 21 11:49:51 CEST 2009


Steven D'Aprano wrote:
> But that one is ugly (that is, I don't think anyone *likes* the syntax, 
> it's just considered the least worst), and some of us consider that its 
> usefulness is dubious, or at least weak. I think the main reason that 
> Python has a ternary if statement is to stop people writing the 
> error-prone:
> 
> cond and x or y
> 
> as a short-circuit ternary if.

That's actually a good point - eliminating the persistent use of buggy
workarounds was definitely one of the major motivations behind accepting
PEP 308.

In this case, there *are* no buggy workarounds: if you want to trap
exception, you have to use a real statement.

Without that additional motivation of bug prevention, I really doubt
this proposal is going to go anywhere.

Cheers,
Nick.

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



More information about the Python-ideas mailing list