Em qua, 1 de jul de 2020 00:56, David Lowry-Duda <da...@lowryduda.com>
escreveu:

> Very similar things could be said about dict.get too, no? It's easy to
> write your own function that does the same thing or to catch an
> exception.
>
> On the other hand, it seems far more likely to miss keys in a dictionary
> than it is to repeatedly mistake indices in a list.


> > Which would be the use cases for this feature?
> >
> > I can't think of one.
>
> I've never missed this feature either. But I would also be interested in
> hearing a dream use case.
>
The usecase is extracting deeply nested data from parsed json.

Missing keys are something that happens on dicts, I want something that is
able to extract data from parsed json, that eliminates the error handling
noise. All this talk elucidates me that this is possible

try:
    v = foo.bar['tar'][0]['zar']
except (LookupError, AttributeError):
   v = None

would suffice in all cases,

>
> - DLD
>
>
> --
> David Lowry-Duda <da...@lowryduda.com> <davidlowryduda.com>
> _______________________________________________
> 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/EUCNY7QZSADRHIGH5KK6BECYGXVDQDRF/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
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/NTD7HRZE4Q3J77D7RTJRLKJ4RX7Y4AEQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to