Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

I do not find in orthodox Christianity one redeeming feature. -- Thomas Jefferson


devel / comp.lang.python / Re: dict.get_deep()

SubjectAuthor
o Re: dict.get_deep()Dieter Maurer

1
Re: dict.get_deep()

<mailman.29.1649005079.20749.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17699&group=comp.lang.python#17699

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: die...@handshake.de (Dieter Maurer)
Newsgroups: comp.lang.python
Subject: Re: dict.get_deep()
Date: Sun, 3 Apr 2022 18:57:50 +0200
Lines: 28
Message-ID: <mailman.29.1649005079.20749.python-list@python.org>
References: <CABbU2U8tdtEW8M7WB0E3nB_9cAHrZNY6cZYWgyjUHrUzMk8yhw@mail.gmail.com>
<25161.53774.591627.704710@ixdm.fritz.box>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de aG4jsvkglcQ0Ib8sbk5iqwdWjWmmHSSC8fdO1LprMf+Q==
Return-Path: <dieter@handshake.de>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.062
X-Spam-Evidence: '*H*': 0.88; '*S*': 0.01; 'this:': 0.03; 'cc:addr
:python-list': 0.09; 'json': 0.09; 'skip:` 10': 0.09;
'cc:name:python list': 0.16; 'defaults': 0.16; 'dict': 0.16;
'instead?': 0.16; 'nested': 0.16; 'skip:> 20': 0.16; 'python':
0.16; 'instead': 0.17; 'implement': 0.19; 'cc:addr:python.org':
0.20; 'received:de': 0.23; 'cc:2**0': 0.25; 'object': 0.26; 'but':
0.32; 'header:In-Reply-To:1': 0.34; 'subject:skip:d 10': 0.35;
'also,': 0.36; 'could': 0.38; 'use': 0.39; 'wrote': 0.39;
'something': 0.40; 'proposal.': 0.62; 'data,': 0.63; 'your': 0.64;
'header:Received:6': 0.67; 'customize': 0.69; 'deeply': 0.69;
'yourself': 0.75; 'carrier': 0.84; 'mapped': 0.84; 'received:88':
0.84; 'sulla': 0.84; 'skip:d 30': 0.86
In-Reply-To: <CABbU2U8tdtEW8M7WB0E3nB_9cAHrZNY6cZYWgyjUHrUzMk8yhw@mail.gmail.com>
X-Mailer: VM 8.0.12-devo-585 under 21.4 (patch 24) "Standard C" XEmacs Lucid
(x86_64-linux-gnu)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <25161.53774.591627.704710@ixdm.fritz.box>
X-Mailman-Original-References: <CABbU2U8tdtEW8M7WB0E3nB_9cAHrZNY6cZYWgyjUHrUzMk8yhw@mail.gmail.com>
 by: Dieter Maurer - Sun, 3 Apr 2022 16:57 UTC

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?
>
>data.get_deep("users", 0, "address", "street")
>
>and also, instead of this
>
>try:
> result = data["users"][0]["address"]["street"]
>except KeyError, IndexError:
> result = "second star"
>
>write this:
>
>data.get_deep("users", 0, "address", "street", default="second star")

You know you can easily implement this yourself -- in your own
`dict` subclass.

You can also customize the JSON decoding (--> `object_hook`)
to determine how a JSON object is mapped to a Python object;
it defaults to `dict` but you could use your own `dict` subclass.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor