[Python-ideas] Re: dict.get_deep()

2021-05-24 Thread Marco Sulla
On Sun, 23 May 2021 at 19:41, Todd wrote: > > The pytoolz/cytoolz project already has this: > https://toolz.readthedocs.io/en/latest/api.html#toolz.dicttoolz.get_in It seems a project that is used by many people. I think that JSON is so much used that that function could be added to the builtin

[Python-ideas] Re: dict.get_deep()

2021-05-23 Thread Todd
The pytoolz/cytoolz project already has this: https://toolz.readthedocs.io/en/latest/api.html#toolz.dicttoolz.get_in On Sun, May 23, 2021, 11:44 Chris Angelico wrote: > On Mon, May 24, 2021 at 1:24 AM MRAB wrote: > > Also, if the first lookup returns a list or a tuple, and an argument can > >

[Python-ideas] Re: dict.get_deep()

2021-05-23 Thread Marco Sulla
On Sun, 23 May 2021 at 17:22, MRAB wrote: > > On 2021-05-23 13:37, Marco Sulla wrote: > > I propose to add a get_deep(*args, default=_sentinel) method to dict. > > > > It can accept a single argument, that must be an iterable, or multiple > > arguments. > > > > The first element must be a key of

[Python-ideas] Re: dict.get_deep()

2021-05-23 Thread Chris Angelico
On Mon, May 24, 2021 at 1:24 AM MRAB wrote: > Also, if the first lookup returns a list or a tuple, and an argument can > be an index of that list, would be make sense to add a similar method to > lists and tuples? Or, better: make it a stand-alone function, not a method of anything. Although

[Python-ideas] Re: dict.get_deep()

2021-05-23 Thread MRAB
On 2021-05-23 13:37, Marco Sulla wrote: I propose to add a get_deep(*args, default=_sentinel) method to dict. It can accept a single argument, that must be an iterable, or multiple arguments. The first element must be a key of the dict. If there's not a second element, the value is returned.

[Python-ideas] Re: dict.get_deep()

2021-05-23 Thread Marco Sulla
On Sun, 23 May 2021 at 15:30, Thomas Grainger wrote: > > seems a bit like https://www.python.org/dev/peps/pep-0505/ > > eg `d?[1]?[0]` No, I do not want to suppress the exception, only to have a way to access a nested object in a complicate dict, for example a dict generated by a JSON. In your

[Python-ideas] Re: dict.get_deep()

2021-05-23 Thread Thomas Grainger
seems a bit like https://www.python.org/dev/peps/pep-0505/ eg `d?[1]?[0]` ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org