Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Stupidity, like virtue, is its own reward" -- William E. Davidsen


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 overriddn

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

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonList@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Variable scope inside and outside functions - global statement
being overridden by assignation unless preceded by reference
Date: Thu, 7 Mar 2024 14:10:11 +1300
Organization: DWM
Lines: 41
Message-ID: <mailman.56.1709773826.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>
<2248adf8-551f-4e86-8de8-be892d5978ed@tompassin.net>
<9c71abb0-b28d-4646-b130-9a4fdd529428@gmail.com>
<da56d0f1-ae1c-4f73-9493-c07f7c6d13c5@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de Rg3NX7jq34+xZOLXMFaFwAIPzC9taNXKzFiAEesKfGmA==
Cancel-Lock: sha1:6F/hcITJO1BjSEH43ShvTm25diw= sha256:gu8R+scfghncdI3XiHL5W5AYjJf8fE2xVR0ngGKZZwk=
Return-Path: <PythonList@DancesWithMice.info>
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=danceswithmice.info header.i=@danceswithmice.info
header.b=gZgX8Qn/; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'entering': 0.05; 'run.':
0.05; 'hitting': 0.07; '=dn': 0.09; 'console,': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'implicit': 0.09; 'shift': 0.09; 'something,': 0.09;
'treated': 0.09; 'tutorial': 0.12; '(eg': 0.16; '(surely': 0.16;
'05:28,': 0.16; 'assumptions': 0.16; 'comparing': 0.16;
'diagnosis': 0.16; 'entirety': 0.16; 'executed': 0.16;
'functions.': 0.16; 'importing': 0.16; 'lesson,': 0.16;
'mentions': 0.16; 'message-id:@DancesWithMice.info': 0.16;
'objective': 0.16; 'received:51.254': 0.16; 'received:51.254.211':
0.16; 'received:51.254.211.219': 0.16; 'received:cloud': 0.16;
'received:rangi.cloud': 0.16; 'scenario,': 0.16; 'subject:being':
0.16; 'subject:reference': 0.16; 'wrote:': 0.16; 'python': 0.16;
'to:addr:python-list': 0.20; 'all,': 0.20; "i've": 0.22; 'code':
0.23; 'run': 0.23; 'idea': 0.24; 'saying': 0.25; 'cannot': 0.25;
'behavior': 0.26; 'solution.': 0.26; 'sense': 0.28; 'environment':
0.29; 'header:User-Agent:1': 0.30; 'module': 0.31; 'review,':
0.31; 'header:Organization:1': 0.31; 'wondering': 0.31; "doesn't":
0.32; '(as': 0.32; 'python-list': 0.32; 'said,': 0.32;
'received:192.168.1': 0.32; 'but': 0.32; 'there': 0.33; 'script':
0.33; 'header:In-Reply-To:1': 0.34; 'failed': 0.35;
'particularly': 0.35; 'usual': 0.35; 'yes,': 0.35; 'request':
0.35; 'missing': 0.37; "skip:' 10": 0.37; "it's": 0.37; 'others':
0.37; 'received:192.168': 0.37; 'two': 0.39; 'still': 0.40;
'(see': 0.40; 'ide': 0.40; 'reports': 0.40; 'something': 0.40;
'try': 0.40; 'should': 0.40; 'above': 0.62; 'brief': 0.62; 'full':
0.64; 'received:51': 0.64; 'earlier': 0.67; 'important.': 0.69;
'manually': 0.69; 'compared': 0.71; 'tools': 0.74; '....': 0.76;
'mode,': 0.76; 'quick': 0.77; 'unusual': 0.81; 'perfect': 0.82;
'learn,': 0.84; 'prototype': 0.84; 'say,': 0.84; 'subject: \n ':
0.84; 'glad': 0.86
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud 9568950C0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1709773817;
bh=bC7VP6fpaSk6CakJQNHG/n2y+gv6msGKvLOH8B+IDWg=;
h=Date:From:Subject:To:References:In-Reply-To:From;
b=gZgX8Qn/3zadfUkWX3e/eO/qgVXELmDJ/N4DC3A6Um2kGvy6YiXV4UXL5qkZk764S
HUaQdSnSv6LVdDv6dCCFb28950MNShkXZKxAZGKlp9W0s7DNPqy+LsM2TlCjrgbBtZ
YCGn0eFOnikSJWZKM2AnjG/hYy7se5FMzBycQaIqcSG8KM0xf5Q7N+V6hsivEGT1BV
zxh02CHGroVT+WYWz9lO56yAYCC2SgPa2gQBWqA+dL3uSxD6LOLK1OOxAnp7U5yKc9
CamjP/Gx9wqIiYr8m5uGeEeuGC+3+ei5LfU1QqboW57U2IzI956+ADuRimEjqAhXeC
m++f73v4laSbA==
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <9c71abb0-b28d-4646-b130-9a4fdd529428@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: <da56d0f1-ae1c-4f73-9493-c07f7c6d13c5@DancesWithMice.info>
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>
<2248adf8-551f-4e86-8de8-be892d5978ed@tompassin.net>
<9c71abb0-b28d-4646-b130-9a4fdd529428@gmail.com>
 by: dn - Thu, 7 Mar 2024 01:10 UTC

On 7/03/24 05:28, Jacob Kruger via Python-list wrote:
....
> So, yes, know this comes across like some form of a scam/joke, or
> list-garbage, since it doesn't make any sense to me at all, but still
> just wondering if missing something, or should I shift over to 3.12 to
> see if if works differently, or just try reinstalling 3.11 from scratch,
> or should I retry the above in something like the VS code console, or a
> different python console, etc.?
Some of the facts, such as HOW the code was being executed were missing
(see earlier request for a cut-down scenario, AND reports from others
saying 'but it works for me').

The idea of importing a module into the REPL and then (repeatedly)
manually entering the code to set-up and execute is unusual (surely type
such into a script (once), and run that (repeatedly). As you say, most
of us would be working from an IDE and hitting 'Run'. Am wondering why
you weren't - but it's not important.

That said, the REPL is the perfect place to learn, experiment, and
prototype - particularly when compared with the facilities of other
language's eco-systems. The entirety of the on-line Tutorial cannot be
wrong! (although, after a quick review, I've failed to see where the
Tutorial mentions the usual development mode, apart from two very brief
asides (the most useful is almost at the very end(?)) - but then (as
they say) the objective is to show the language!

The lesson-learned is that there are different 'environments' and
different ways of building the environment in which the code will run.
That's a valuable lesson, and full of subtlety!

Glad to see that comparing id()s was useful - for diagnosis but not
solution. Other tools might include the locals() and globals()
functions. You may also have detected that many of us try to avoid
globals and the implicit assumptions about the behavior of mutable
collections (eg lists) when treated as 'global'. Then there are
"closures", the "LEGB" rule, namespaces, scope, and ...

--
--
Regards,
=dn

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor