Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Imagination is more important than knowledge. -- Albert Einstein


devel / comp.lang.python / Re: A Single Instance of an Object?

SubjectAuthor
o Re: A Single Instance of an Object?Ivan \"Rambius\" Ivanov

1
Re: A Single Instance of an Object?

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rambiusparkisanius@gmail.com (Ivan \"Rambius\" Ivanov)
Newsgroups: comp.lang.python
Subject: Re: A Single Instance of an Object?
Date: Mon, 11 Mar 2024 17:37:34 -0400
Lines: 43
Message-ID: <mailman.89.1710193069.3452.python-list@python.org>
References: <CAE9rwzOnEiBSf_m19EQByXQ_Qyk=GkiEzBUf=WMfaeZvR9102g@mail.gmail.com>
<1a49ecb0-2a5f-4758-92d1-a70d3d3dc651@DancesWithMice.info>
<CAE9rwzO8oGz3pzT1SeanUd_bi78uwaZR9BuzFHu5p9tHiKzb3A@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de nvJenFPjIYgiz3i+skUZmg1Th87CPtJ2zCLptmz2MTzQ==
Cancel-Lock: sha1:uFty1MSBWz7hUXjhUDJI7kgmAjw= sha256:VJkoJGjnbh3eAS2qdZK8pd/5m6d5jLJdRPTC0s5d9Lg=
Return-Path: <rambiusparkisanius@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=mQWtcfmD;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.039
X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'def': 0.04; 'variable':
0.05; 'mar': 0.07; 'cc:addr:python-list': 0.09; 'lookup': 0.09;
'cc:no real name:2**0': 0.14; 'import': 0.15; '"cache"': 0.16;
'(it': 0.16; '2024': 0.16; 'outline:': 0.16; 'refactoring': 0.16;
'variable.': 0.16; 'wrote:': 0.16; 'cc:addr:python.org': 0.20;
'skip:_ 10': 0.22; 'code': 0.23; 'cc:2**0': 0.25; '11,': 0.26;
'question': 0.32; 'python-list': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35; 'mon,':
0.36; 'change': 0.36; 'currently': 0.37; 'class': 0.37; 'use':
0.39; 'hello,': 0.40; 'method': 0.61; 'here': 0.62; 'research':
0.64; 'definition': 0.64; 'ivan': 0.64; 'your': 0.64; 'within':
0.69; 'global': 0.73; 'unit': 0.81; 'mega': 0.84; 'received:mail-
lf1-x133.google.com': 0.84; 'rid': 0.84; 'them!': 0.84; 'url-
ip:195/8': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1710193068; x=1710797868; darn=python.org;
h=content-transfer-encoding:cc:to:subject:message-id:date:from
:in-reply-to:references:mime-version:from:to:cc:subject:date
:message-id:reply-to;
bh=mOqH5nRyIwTA650hu4rgmyBX2DWJE6szTFpyvwnCtf4=;
b=mQWtcfmDa1UkCkNDQGVLD/sstfBRLTsBfRWnUXP8S73IlsBBRicmbzKbK6INwOlPNZ
U1qSYwIY8JXT2H4MgBMVcLsTiRoskNr/JuUkH/GzdW7eiuDmOod1w/eyvew0g5TkO9T9
seZhV7p6B+udlBVa7OXHyTZ3h7dsIJXKo4r53RslhbEN9bGM6o4rKhmfW7FDHExu98gc
v5uC25V0sANBORQj4CAV43CM75cn53re84CXqlkPZQezZnzEZL4FLioVi9NS4i+L5YRq
KzGV9122rVuO2iGLyJtLz0xV7b0XxjGYJxTueJfC3RM0NM8yRfK1frMvVK79XQP/vVbM
rByg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1710193068; x=1710797868;
h=content-transfer-encoding:cc:to:subject:message-id:date:from
:in-reply-to:references:mime-version:x-gm-message-state:from:to:cc
:subject:date:message-id:reply-to;
bh=mOqH5nRyIwTA650hu4rgmyBX2DWJE6szTFpyvwnCtf4=;
b=T62oYZcSrx9I6CFGAeHBvC0frwQ2K1zL6yz6txRNYuLjUmla9z8Eb+/YED9mrYqzNW
tMsWu7a4XSENCp3QTVaxz6lJ6iMAgiEAXGWRprz93dhAb7fMz4RljUxPALjy4UwJ2MDT
xoOYbuYrJ8emEMcyY5F8UX12F9iC83wZpkuuk5tytGBCAKo/42dYIhtyJj8B0OnU7ay/
BlDyGnrenjrID2xVms44la2+m8MucfQWF+UxXb0E8+KZxTUQmKYBPnwY6juUnawnKQRu
3gd20MNqDqn/mkVc35a8dXWKbZM35yTIOz+F8F5kcPcxokCzpnSUrURtXW89rkqLqZ4a
fvMg==
X-Gm-Message-State: AOJu0Yw4OEnqUtNaazEMk054Khjxs8vfz5l3RLEW9o8+FcToCIKHDU7a
7PdjcjkxU+dlM2eNSqgsqWiV5tBnx7V6ychG/ngswDP9RYtH7hPGdHVQ5wwvFC570sLjXV+DjBd
KtUAf4uJmh3vqF1dY3UjLoSqmK7Azh/ND
X-Google-Smtp-Source: AGHT+IFLStni87gxoAlP3b0peGy/zoIp06rHjwVMXTp449fKPUfm1ZpdL2hz4LMRw1gvr/p8sYQ6BM9SRr9UsAlxk5g=
X-Received: by 2002:a05:6512:3baa:b0:513:b102:7d93 with SMTP id
g42-20020a0565123baa00b00513b1027d93mr2433630lfv.24.1710193067431; Mon, 11
Mar 2024 14:37:47 -0700 (PDT)
In-Reply-To: <1a49ecb0-2a5f-4758-92d1-a70d3d3dc651@DancesWithMice.info>
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: <CAE9rwzO8oGz3pzT1SeanUd_bi78uwaZR9BuzFHu5p9tHiKzb3A@mail.gmail.com>
X-Mailman-Original-References: <CAE9rwzOnEiBSf_m19EQByXQ_Qyk=GkiEzBUf=WMfaeZvR9102g@mail.gmail.com>
<1a49ecb0-2a5f-4758-92d1-a70d3d3dc651@DancesWithMice.info>
 by: Ivan \Rambius\ Ivano - Mon, 11 Mar 2024 21:37 UTC

On Mon, Mar 11, 2024 at 5:06 PM dn via Python-list
<python-list@python.org> wrote:
>
> Good question Rambius!
>
> On 12/03/24 09:53, Ivan "Rambius" Ivanov via Python-list wrote:
> > Hello,
> >
> > I am refactoring some code and I would like to get rid of a global
> > variable. Here is the outline:
> >
> > import subprocess
> >
> > CACHE = {}
>
> First thought: don't reinvent-the-wheel, use lru_cache
> (https://docs.python.org/3/library/functools.html)
>
>
> > The global cache variable made unit testing of the lookup(key) method
> > clumsy, because I have to clean it after each unit test. I refactored
> > it as:
> >
> > class Lookup:
> > def __init__(self):
> > self.cache = {}
> >
>
> Change "cache" to be a class-attribute (it is currently an instance.
>
> Then, code AFTER the definition of Lookup can refer to Lookup.cache,
> regardless of instantiation, and code within Lookup can refer to
> self.cache as-is...
>

Thank you for your suggestions. I will research them!

Regards
rambius

--
Tangra Mega Rock: http://www.radiotangra.com

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor