On Thu, Aug 6, 2020 at 10:56 PM Jonathan Grant <jonathanallengr...@gmail.com> wrote: > > Hey all, > > Instead of writing this: > > ``` > try: > return my_dict[“a”][“b”][“c”][“d”] > except: > return “some default” > ``` > > Or this > ``` > return my_dict.get(“a”, {}).get(“b”, {}),get(“c”, {}).get(“d”, “some default”) > ``` > > I propose we allow for an inline exception handler, like `eor`: > ``` > return my_dict[“a”][“b”][“c”][“d”] eor “some default” > ``` > > This works very similar to what we already have with `or`, and makes code > much more compact and readable.
Have a look at PEP 463, which looks into this in some detail. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/AG56KZGWNXQKB32HP5DXCDHMNPPU3UEF/ Code of Conduct: http://python.org/psf/codeofconduct/