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

Ron Adam rrr at ronadam.com
Sat Aug 22 03:28:04 CEST 2009

Greg Ewing wrote:
> Steven D'Aprano wrote:
>> Others have suggested that the colon should be dropped. I dislike that 
>> idea, because there's nothing but whitespace delimiting the list of 
>> exceptions from the except-expression:
> I agree. Even if it can be parsed unambiguously, it's
> going to seem weird and confusing to a human.
> So far I haven't seen anything I like better than
>   <expr> except <value> if <exception>
> despite the fact that it uses the words 'except'
> and 'if' in a different way than elsewhere.

Possibly the only way to do this within those constraints is a purely 

     value = (expr1 :exception: expr2)

Sense most people (and editors) recognize exceptions names easily, there 
really isn't a strong need to use the key word "except" in an expression 
like this.

The colons in this case can be considered to be similar to slice syntax. 
And if the colons are still considered bad, possibly some other symbol 
could be used.


More information about the Python-ideas mailing list