[Python-ideas] except expression

Chris Angelico rosuav at gmail.com
Thu Feb 20 14:31:39 CET 2014


On Fri, Feb 21, 2014 at 12:23 AM, Ron Adam <ron3200 at gmail.com> wrote:
> The expression doesn't need to be just too terms, it could be something more
> complex.
>
>       (except KeyError: d1[key] or d2[key] or d3[key] or None)
>
>
> Would give the first dictionary lookup that doesn't raise KeyError or None.
>
> Because the exception paths and data paths don't overlap, they could be
> dictionaries containing exception instances and it would still work.

Okay. I think I follow. The way to spell that in the current proposal is:

d1[key] except KeyError: (d2[key] except KeyError: (d3[key] except
KeyError: None))

which is rather more verbose. On the other hand, the syntax you have
requires magic around the 'or' keyword.

ChrisA


More information about the Python-ideas mailing list