Em qua, 1 de jul de 2020 00:56, David Lowry-Duda
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
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/EUCNY7... Code of Conduct: http://python.org/psf/codeofconduct/