[Python-ideas] except expression

אלעזר elazarg at gmail.com
Thu Feb 20 14:41:45 CET 2014


2014-02-20 15:31 GMT+02:00 Chris Angelico <rosuav at gmail.com>:
>
> 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.
>
Perhaps it should be a colon-seperated list:

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

Or maybe a semicolon.

    (except KeyError: d1[key] ; d2[key] ; d3[key] ; None)
---
Elazar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140220/00947258/attachment.html>


More information about the Python-ideas mailing list