[Python-ideas] except expression

Paul Moore p.f.moore at gmail.com
Thu Feb 13 12:36:55 CET 2014


On 13 February 2014 11:25, spir <denis.spir at gmail.com> wrote:
> I don't see any issue with:
>     phone = addressbook[name] except "Unknown" if KeyError
>     phone = addressbook[name] except "Unknown" if KeyError as e
> It is similar in syntax and meaning with if-expressions, with the first
> keyword 'except' obviously making all the difference we need.

What I dislike about this variant is that in a normal try statement,
the exception goes after the "except" keyword. Here, it's the
alternative value that goes there. I find that very easy to misread.

Personally, I quite like "EXPR except EXCEPTIONTYPE return VALUE" if
we have to stick with existing keywords. If I had free rein I might go
for a new keyword "then" instead of "return".

Paul


More information about the Python-ideas mailing list