Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Never give in. Never give in. Never. Never. Never." -- Winston Churchill


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

SubjectAuthor
o Re: dict.get_deep()Chris Angelico

1
Re: dict.get_deep()

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: dict.get_deep()
Date: Mon, 4 Apr 2022 07:52:14 +1000
Lines: 43
Message-ID: <mailman.34.1649022747.20749.python-list@python.org>
References: <CABbU2U8tdtEW8M7WB0E3nB_9cAHrZNY6cZYWgyjUHrUzMk8yhw@mail.gmail.com>
<25161.53774.591627.704710@ixdm.fritz.box>
<CABbU2U8dbs-0R2ASwpAjHdh4Hbp86jSu2TkC095=+sk5eELMMw@mail.gmail.com>
<CAPTjJmrEf5xh9g2YFp24jaezmfocO_LA_HAyjQcyooej9XaDHA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de P0p+N98rBPBq3CazrXUDewbiEgiARWJR5hnql4aiKUrw==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=HeofgTWj;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'this:': 0.03; 'def': 0.04;
'2022': 0.05; 'queue': 0.07; 'reason:': 0.07; 'sun,': 0.07;
'idle': 0.09; 'json': 0.09; 'received:209.85.128.46': 0.09;
'received:mail-wm1-f46.google.com': 0.09; 'append': 0.16; 'call,':
0.16; 'chrisa': 0.16; 'dict': 0.16; 'dieter': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'subtly': 0.16; 'wrote:': 0.16; 'uses': 0.19; 'implement': 0.19;
'to:addr:python-list': 0.20; 'version': 0.23; 'list,': 0.24;
'backed': 0.26; 'function': 0.27; 'think': 0.32; "doesn't": 0.32;
'question': 0.32; 'elements': 0.32; 'empty': 0.32; "wouldn't":
0.32; 'message-id:@mail.gmail.com': 0.32; 'but': 0.32; 'there':
0.33; 'path': 0.33; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; '"if': 0.35; 'subject:skip:d 10':
0.35; 'from:addr:gmail.com': 0.35; 'mon,': 0.36; 'lists': 0.37;
"it's": 0.37; 'received:209.85': 0.37; 'error,': 0.38;
'received:209': 0.39; 'use': 0.39; 'something': 0.40; 'higher':
0.60; 'method': 0.61; 'your': 0.64; 'tool': 0.65; 'back': 0.67;
'etc,': 0.69; 'only.': 0.69; "you'll": 0.73; 'yourself': 0.75;
'sulla': 0.84; 'usage.': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=nTo551WNFI6VZ2FRZdgGW2L6CvRqCvkCbqNMWEZFqc8=;
b=HeofgTWjm5k6c0sDPTW5Ssm5HINzKMCAhqBhAAu8Zdh6qp+4t0oAb6XQkejCLUVBUp
kzu5gZy6swCeuINiYOeBBaM4KEI2cUwf1AtmbWvqaU2IfPtuLkvtRbIx94Kc2mjYCeMq
k3NjpvCeFAr2PU7RQVEFkrU1/f/FyMxMzk0Z0LkCNt7N3KRNojhHnksAZkMRUC0JVmBL
Q31r0iDtUgBr9/5WsMV6HUhVzU4C7nlxBkfTKqk1zWr2eFdqM2xGdgWaqF+VxuqjfQYr
jEDQaLot4n5H68gSiILYyRpZ5gbSmKyjkMZ2fa3R6aKDqWI/Uxz1Xrg/tE2zQaHyuYmC
dftw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=nTo551WNFI6VZ2FRZdgGW2L6CvRqCvkCbqNMWEZFqc8=;
b=FcjbfKiP70eCtoL5mHahcd3yrQndZz48b30f6AUh7B4jp4pyKJggxAKQI/abNxZBr/
qqWqWuINqhuZa4B2KqXrn3S0TM/PynFEcssHwSxYf6jh5pMf1sbR63k2dRtNgK2+TWlP
g/JZ5Q0Cjoeq9DjJIcf7KleuskoVQlEuTahA2htStkmtj3G9uSYTJ4DRfforK5RysIoP
BglGhr7gsrR3Fk7Fvyp/jwInXLOSbEF0df1+d9ZLUyMNlcjyuGciAQtWV0od5lXQoz9/
zn/r5QfHZ4PsA9vbiMtxn4O+WAWFQw7c/26S0BHjXBITxLHtgko6VARKd/4iFgTgbyTk
nBJw==
X-Gm-Message-State: AOAM531mZpoiU2tKDQsKtuLh1hmY3Q4ieLBGvyWuHWDdNuZdNfYJOcqt
VjANBBz8xLDj8ALUe+Sqv0Y20y15EF0+P98dXdZCPomF
X-Google-Smtp-Source: ABdhPJxGPaB3B+bo/JydmFzHmGlaXcGfNioYfFNrHT6Zl+3l3JPFgDXfoMQn5zGtTyhcxcT7g/ZLV9UHrFFijdskS7Q=
X-Received: by 2002:a1c:7411:0:b0:38c:b51e:8d7b with SMTP id
p17-20020a1c7411000000b0038cb51e8d7bmr16764135wmc.148.1649022745420; Sun, 03
Apr 2022 14:52:25 -0700 (PDT)
In-Reply-To: <CABbU2U8dbs-0R2ASwpAjHdh4Hbp86jSu2TkC095=+sk5eELMMw@mail.gmail.com>
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: <CAPTjJmrEf5xh9g2YFp24jaezmfocO_LA_HAyjQcyooej9XaDHA@mail.gmail.com>
X-Mailman-Original-References: <CABbU2U8tdtEW8M7WB0E3nB_9cAHrZNY6cZYWgyjUHrUzMk8yhw@mail.gmail.com>
<25161.53774.591627.704710@ixdm.fritz.box>
<CABbU2U8dbs-0R2ASwpAjHdh4Hbp86jSu2TkC095=+sk5eELMMw@mail.gmail.com>
 by: Chris Angelico - Sun, 3 Apr 2022 21:52 UTC

On Mon, 4 Apr 2022 at 05:19, Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:
>
> On Sun, 3 Apr 2022 at 18:57, Dieter Maurer <dieter@handshake.de> 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.

I think not, for a slightly different reason: There are many small
variants of it that might be needed. For instance, I have a system of
persistent data that is backed by a JSON file, and I have a path
function that does this:

def path(self, *parts):
ret = self.data # always a dict
for part in parts:
if part not in ret:
ret[part] = {}
self.save() # queue a save for the next idle time
ret = ret[part]
return ret

It's used something like this:

cfg = persist.path("channels", channame, "alerts", "host")

and if there had previously been no configs, you'll get back an empty
dict, not None, not an error, etc.

This version uses dictionaries only. A version that also supports
lists would require one more check before the "part not in ret" check
(probably something like "if this is a list, and you're asking for an
index higher than the current one, append elements till we get
there"), and a version that doesn't autosave wouldn't need the save()
call, etc, etc, etc.

IMO this is an extremely useful tool to have in your own toolbelt, but
I actually don't use *identical* versions of it very often. They're
usually subtly different from each other, due to the slight
differences in usage.

ChrisA

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor