On 2022-04-03 23:17:04 +0200, Marco Sulla wrote:
> On Sun, 3 Apr 2022 at 21:46, Peter J. Holzer wrote:
> > > > data.get_deep("users", 0, "address", "street", default="second star")
> >
> > Yep. Did that, too. Plus pass the final result through a function before
> > returning it.
>
> I didn't unde
On 03Apr2022 21:45, Peter J. Holzer wrote:
>Yup. I need something like this quite frequently, so I wrote a little
>utility function (which I copy and paste into lots of code - I probably
>should package that up, but a package with a single short function feels
>weird).
Start with one with a sligh
-- Forwarded message --
From: Marco Sulla
Date: Apr 2, 2022 22:44
Subject: dict.get_deep()
To: Python List <>
Cc:
A proposal. Very often dict are used as a deeply nested carrier of
data, usually decoded from JSON.
data["users&qu
ns offered.
-Original Message-
From: Kirill Ratkin via Python-list
To: python-list@python.org
Sent: Mon, Apr 4, 2022 3:40 am
Subject: Re: dict.get_deep()
Hello,
Yes, I misunderstood as well because started to think about pattern
matching which is good but this is not subject the question
asort of built-in data
structure but could work for one of many variantsalready implemented in modules.
-Original Message-
From: Marco Sulla
To: Peter J. Holzer
Cc: python-list@python.org
Sent: Sun, Apr 3, 2022 5:17 pm
Subject: Re: dict.get_deep()
On Sun, 3 Apr 2022 at 21:46, Peter
y implemented in modules.
-Original Message-
From: Marco Sulla
To: Peter J. Holzer
Cc: python-list@python.org
Sent: Sun, Apr 3, 2022 5:17 pm
Subject: Re: dict.get_deep()
On Sun, 3 Apr 2022 at 21:46, Peter J. Holzer wrote:
>
> > > data.get_deep("users", 0, "add
Marco Sulla wrote at 2022-4-3 21:17 +0200:
>On Sun, 3 Apr 2022 at 18:57, Dieter Maurer wrote:
>> You know you can easily implement this yourself -- in your own
>> `dict` subclass.
>
>Well, of course, but the question is if such a method is worth to be
>builtin, in a world imbued with JSON. I suppo
On Mon, 4 Apr 2022 at 05:19, Marco Sulla wrote:
>
> On Sun, 3 Apr 2022 at 18:57, Dieter Maurer wrote:
> > You know you can easily implement this yourself -- in your own
> > `dict` subclass.
>
> Well, of course, but the question is if such a method is worth to be
> builtin, in a world imbued with
On Sun, 3 Apr 2022 at 21:46, Peter J. Holzer wrote:
>
> > > data.get_deep("users", 0, "address", "street", default="second star")
>
> Yep. Did that, too. Plus pass the final result through a function before
> returning it.
I didn't understand. Have you added a func parameter?
> I'm not sure whet
On 2022-04-03 17:58:09 +0300, Kirill Ratkin via Python-list wrote:
> 02.04.2022 23:44, Marco Sulla пишет:
> > A proposal. Very often dict are used as a deeply nested carrier of
> > data, usually decoded from JSON. Sometimes I needed to get some of
> > this data, something like this:
> >
> > data["
On Sun, 3 Apr 2022 at 18:57, Dieter Maurer wrote:
> You know you can easily implement this yourself -- in your own
> `dict` subclass.
Well, of course, but the question is if such a method is worth to be
builtin, in a world imbued with JSON. I suppose your answer is no.
--
https://mail.python.org
On Sun, 3 Apr 2022 at 16:59, Kirill Ratkin via Python-list
wrote:
>
> Hi Marco.
>
> Recently I met same issue. A service I intergated with was documented
> badly and sent ... unpredictable jsons.
>
> And pattern matching helped me in first solution. (later I switched to
> Pydantic models)
>
> For
Marco Sulla wrote at 2022-4-2 22:44 +0200:
>A proposal. Very often dict are used as a deeply nested carrier of
>data, usually decoded from JSON. Sometimes I needed to get some of
>this data, something like this:
>
>data["users"][0]["address"]["street"]
>
>What about something like this instead?
>
>
On 2022-04-03 at 18:01:58 +0300,
Kirill Ratkin via Python-list wrote:
> It seems 'case if' should help with types:
>
> case {"users": [{"address": {"street": street}}]} if isinstance(street,
> str):
reduce(lambda x, y: x[y], ["users", 0, "address", "street"], data)
Unless it's y[x] rather than
On Mon, 4 Apr 2022 at 00:59, Kirill Ratkin via Python-list
wrote:
>
> Hi Marco.
>
> Recently I met same issue. A service I intergated with was documented
> badly and sent ... unpredictable jsons.
>
> And pattern matching helped me in first solution. (later I switched to
> Pydantic models)
>
> For
To my previous post.
It seems 'case if' should help with types:
case {"users": [{"address": {"street": street}}]} if isinstance(street,
str):
:)
// BR
02.04.2022 23:44, Marco Sulla пишет:
A proposal. Very often dict are used as a deeply nested carrier of
data, usually decoded from JSON.
Hi Marco.
Recently I met same issue. A service I intergated with was documented
badly and sent ... unpredictable jsons.
And pattern matching helped me in first solution. (later I switched to
Pydantic models)
For your example I'd make match rule for key path you need. For example:
data = {
A proposal. Very often dict are used as a deeply nested carrier of
data, usually decoded from JSON. Sometimes I needed to get some of
this data, something like this:
data["users"][0]["address"]["street"]
What about something like this instead?
data.get_deep("users", 0, "address", "street")
and
18 matches
Mail list logo