On Mon, Oct 18, 2021 at 6:49 PM Paul Moore <p.f.mo...@gmail.com> wrote:

> On Mon, 18 Oct 2021 at 19:29, Guido van Rossum <gu...@python.org> wrote:
> > y = None  # Default
> > if config is not None:
> >   handler = config.get("handler")
> >   if handler is not None:
> >     parameters = handler.get("parameters")
> >     if parameters is not None:
> >       y = parameters.get("y")
>
> For this particular usage, I'd much rather have a functional API, like
> y = get_config(config, "handler", "parameters", "y")
>

I agree with Paul here... and am pretty sure I did the last time this went
around.  Whenever the issue comes up, it's about JSON.  Or *maybe* about
something very similar that goes by another name or format details.

And there already exists a pretty good, pretty standard, approach called
JSONPath that deals with exactly this kind of thing.  This, in turn, is
largely the same as XPath which serves the same role for XML documents.

I don't think it necessarily needs to be in the standard library, but the
mini-language for extracting data from trees with frequently missing
branches can very well simply be a mini-language.  It'll wind up a lot like
XPath/JSONPath, but something a little bit different could be good too.

-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/S5Q4OVZIJUQ5AG4HNIRGN4NALCNJGWOW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to