Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Not only Guinness - Linux is good for you, too. -- Banzai on IRC


devel / comp.lang.python / Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

SubjectAuthor
o Re: Variable scope inside and outside functions - global statement being overridRoel Schroeven

1
Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: roel@roelschroeven.net (Roel Schroeven)
Newsgroups: comp.lang.python
Subject: Re: Variable scope inside and outside functions - global statement
being overridden by assignation unless preceded by reference
Date: Wed, 6 Mar 2024 18:33:17 +0100
Lines: 27
Message-ID: <mailman.53.1709746402.3452.python-list@python.org>
References: <aff560df-2f57-47d9-ad81-74c21960c21d@gmail.com>
<0ccad7a9-eaba-48e6-b972-d89e5a930c11@DancesWithMice.info>
<db322a1b-2d29-4b67-9d5c-3e8d8737c0f5@gmail.com>
<b0b253c4-5e9e-44a3-975a-11851009d52c@wichmann.us>
<cbaf27c2-d2cb-4de1-a1c0-02a9fc9bf252@gmail.com>
<2007e9a9-01e9-48fd-b060-56b9ac4db4c9@roelschroeven.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 5CyVenHiXf1BD5ttlnUYtQW0BMmkd3HQ/Y0gPJ9SPg8w==
Cancel-Lock: sha1:f18nxfke8Q5LrjHsVkkxu80wt2o= sha256:NG/2Jda9H6MGrgVyrfdB+Czhg4bAXpQhRPSMkX93ePw=
Return-Path: <roel@roelschroeven.net>
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=roelschroeven.net header.i=@roelschroeven.net
header.b=tq/lOoI7; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'class.': 0.07; 'modules':
0.07; 'methods,': 0.09; 'namespace': 0.09; 'slides': 0.09;
'theory': 0.09; 'import': 0.15; 'possible,': 0.15; '"there': 0.16;
"'import": 0.16; 'directly,': 0.16; 'happening.': 0.16;
'received:10.202': 0.16; 'received:10.202.2': 0.16;
'received:10.202.2.163': 0.16; 'received:64.147': 0.16;
'received:64.147.123': 0.16; 'received:compute7.internal': 0.16;
'received:internal': 0.16; 'received:messagingengine.com': 0.16;
'restaurant': 0.16; 'schreef': 0.16; 'sounds': 0.16;
'subject:being': 0.16; 'subject:reference': 0.16; 'python': 0.16;
'to:addr:python-list': 0.20; "what's": 0.22; 'anyone': 0.25;
'object': 0.26; 'function': 0.27; 'old': 0.27; '>>>': 0.28;
'fact': 0.28; 'header:User-Agent:1': 0.30; 'module': 0.31;
'here,': 0.32; 'there': 0.33; 'same': 0.34; 'header:In-Reply-
To:1': 0.34; 'yes,': 0.35; 'this.': 0.37; 'use': 0.39; 'to.':
0.39; 'still': 0.40; 'something': 0.40; 'ever': 0.63; 'between':
0.63; 'look': 0.65; 'prevent': 0.67; 'received:64': 0.67;
'exactly': 0.68; 'url-ip:67/8': 0.69; 'global': 0.73; 'states':
0.80; 'subject: \n ': 0.84; 'instantly': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
roelschroeven.net; h=cc:content-transfer-encoding:content-type
:content-type:date:date:from:from:in-reply-to:in-reply-to
:message-id:mime-version:references:reply-to:subject:subject:to
:to; s=fm3; t=1709746397; x=1709832797; bh=uaahUkC4a67EzOzQKMN+l
NpcSfBC+WwcHatCXb5l/iY=; b=tq/lOoI7LvOoZYQMGDJ/ZX+F2CX3NJuHbHu1D
jGqCiqc53mpz93/3QKBQkqrqHe8V6OQ2EkZP3RJcMAnPUEeNjttSrHVHIOuI3lv5
f6xpqb0fLU6Q7UAxdLZBsFDXH8R4XwzwnlOxou709f79Ng6OQ6Z3pDwN0zKD76L3
N1OiY8mhb5N+oUpkyIFIyFTpS0y3TTi7aqgTi/bZaWsj4e927PX0uWedzjZ4+oKg
E3f1Ar6CaBBcJYhSy5agx1BzkylGgeIn7C3lmic21jfFjZu4KxZwyay3AZmVubC8
6pBcHENJzg5uu4knTu05EZEOPYOULnJuEkzzmxfzlPpcRk1Kg==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
messagingengine.com; h=cc:content-transfer-encoding:content-type
:content-type:date:date:feedback-id:feedback-id:from:from
:in-reply-to:in-reply-to:message-id:mime-version:references
:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy
:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1709746397; x=
1709832797; bh=uaahUkC4a67EzOzQKMN+lNpcSfBC+WwcHatCXb5l/iY=; b=d
fc7RgoOH7w7M6OGkXcbA05u7SFuLlSq05SQ0tulN/MVpRD6G6c27VaJ4LmxjlYVX
LaR57jIWU8ivPx7g0lDjBYaKhwd7W606fA3X3x2EaQ9Ej0VwgxwLhBfXOmQQuGAa
lqJ3e6AXfxuRP6ZrRSwBO+J403FsJPsyBdBu/Lp5iDcKCEOFI+cTdNMY2Tnlb4Bv
V/Z/KohfVjVN5P4a54JQe2Y1zYTu3eNBt8LAdABu+9CLQG6WdZvZvJsd2p2NmAaY
5CiCF1GZlYWOtsQGwqVQosP84yEi/mI1vBXgD/ZD5TF24OLdmooogBvKdT//3uwf
NUufClWb0Lw8OoSLkDV8A==
X-ME-Sender: <xms:3ajoZV82H2HxX3VZCkrG3Unp5fVYeobAbGtSTTrkMU3Q7ZaoiGidZw>
<xme:3ajoZZucrS6Wyb7t8f0sJLRBfWFhyqdxWiunHxS42y1pyLfVUyHJ71elYX7BMYsYz
9Gwlar2yJ2V>
X-ME-Received: <xmr:3ajoZTBI45p2HDGEAOoS9p7Gm_leoQSKgPPh66HmA81oRNjoWPkRmpX4eWw0LT8xA4m3jNsLKDKcnn0G8-p7HQy7oPt8SqxzpAs4SLdPRcoyYJ0>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledriedugdelkecutefuodetggdotefrodftvf
curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu
uegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesthejre
dttddvjeenucfhrhhomheptfhovghlucfutghhrhhovghvvghnuceorhhovghlsehrohgv
lhhstghhrhhovghvvghnrdhnvghtqeenucggtffrrghtthgvrhhnpeetheduteejleffle
dvuddvvddulefhvdeuleejffelvdehvedtvddvvdekleeutdenucffohhmrghinhepnhgv
uggsrghttghhvghluggvrhdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrh
grmhepmhgrihhlfhhrohhmpehrohgvlhesrhhovghlshgthhhrohgvvhgvnhdrnhgvth
X-ME-Proxy: <xmx:3ajoZZdIxJbKfH540viMQpxl8LaA7CB7OvvhPzpUsw9Cme0bzyhKQA>
<xmx:3ajoZaNWQqSo4fhKLb9vQgy9bTuAi1L1UihECbC39gJoOrD-VaEt3A>
<xmx:3ajoZbnxP0OCCpOI-VLGL94z-EhodQ50zYnapq1Ky9xEpudfuc5Kcw>
<xmx:3ajoZc0vjbqYbsQRSfRhTMkjuLtjzNcPbwt2KD4N0EfcxRgvxDX-Xq0jQnk>
Feedback-ID: i8e5b41ae:Fastmail
User-Agent: Mozilla Thunderbird
Content-Language: nl, en-US
In-Reply-To: <cbaf27c2-d2cb-4de1-a1c0-02a9fc9bf252@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: <2007e9a9-01e9-48fd-b060-56b9ac4db4c9@roelschroeven.net>
X-Mailman-Original-References: <aff560df-2f57-47d9-ad81-74c21960c21d@gmail.com>
<0ccad7a9-eaba-48e6-b972-d89e5a930c11@DancesWithMice.info>
<db322a1b-2d29-4b67-9d5c-3e8d8737c0f5@gmail.com>
<b0b253c4-5e9e-44a3-975a-11851009d52c@wichmann.us>
<cbaf27c2-d2cb-4de1-a1c0-02a9fc9bf252@gmail.com>
 by: Roel Schroeven - Wed, 6 Mar 2024 17:33 UTC

Op 6/03/2024 om 17:40 schreef Jacob Kruger via Python-list:
> >>> from scoping2 import *
Ah yes, that explains what's happening. After that statement, the name
dt_expiry in the current namespace is bound to the same object that the
name dt_expiry in the namespace of module scoping2 is bound to. Function
do_it re-binds that last one to a new one, with the new value; name
dt_expiry in the current namespace is still bound to the old object. (If
all of that sounds like gibberish, have a look at "Facts and myths about
Python names and values" (text:
https://nedbatchelder.com/text/names.html; slides and video:
https://nedbatchelder.com/text/names1.html)

I would advice not to use 'import *', if at all possible, for multiple
reasons, one of which is to prevent problems like this.

I would also advice not to use global variables from other modules
directly, and in fact would advice to minimize the use of globals in
general as much as possible. If you need to keep state between methods,
it might be better to use a class.

--
"There is a theory which states that if ever anyone discovers exactly what the
Universe is for and why it is here, it will instantly disappear and be
replaced by something even more bizarre and inexplicable.
There is another theory which states that this has already happened."
-- Douglas Adams, The Restaurant at the End of the Universe

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor