Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Catch a wave and you're sitting on top of the world." -- The Beach Boys


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 overridJacob Kruger

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

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: jacob.kruger.work@gmail.com (Jacob Kruger)
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 10:23:27 +0200
Lines: 85
Message-ID: <mailman.58.1709799818.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>
<4Tqsp41DHBznTq9@mail.python.org>
<e8fd7bbc-b52a-4a0d-8934-c7c5630cde20@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de WbkQsukHKUqViF/Jq7QWnQl4SHnC6BXT7TkUoWSYiqJA==
Cancel-Lock: sha1:7O06w/JUo+eer0MIsRnFPU71TXU= sha256:58lWLLUVR/mVzCf+dcvWlvLp1uru5SbsgsppT3mGg8s=
Return-Path: <jacob.kruger.work@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=EfVTxMa1;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.061
X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'def': 0.04; 'entering':
0.05; 'hitting': 0.07; 'example:': 0.09; 'import': 0.15;
"'import": 0.16; "'python": 0.16; '(surely': 0.16; 'classes,':
0.16; 'importing': 0.16; 'modules,': 0.16; 'print(x)': 0.16;
'subject:being': 0.16; 'subject:reference': 0.16; 'such,': 0.16;
'wrote:': 0.16; 'python': 0.16; 'grant': 0.17; 'message-
id:@gmail.com': 0.18; 'to:addr:python-list': 0.20; 'maybe': 0.22;
'way.': 0.22; 'code': 0.23; 'command': 0.23; 'run': 0.23; 'idea':
0.24; 'again,': 0.26; 'behavior': 0.26; '>>>': 0.28; 'mostly':
0.28; 'header:User-Agent:1': 0.30; 'module': 0.31; 'wondering':
0.31; 'think': 0.32; "doesn't": 0.32; 'python-list': 0.32; 'skip:-
60': 0.32; 'unless': 0.32; 'received:192.168.1': 0.32; 'but':
0.32; 'script': 0.33; 'header:In-Reply-To:1': 0.34;
'received:google.com': 0.34; 'trying': 0.35; 'usual': 0.35;
'yes,': 0.35; 'from:addr:gmail.com': 0.35; 'using': 0.37; "it's":
0.37; 'received:192.168': 0.37; 'thanks': 0.38; 'text': 0.39;
"we've": 0.39; 'use': 0.39; 'still': 0.40; 'beginning': 0.40;
'explain': 0.40; 'forms': 0.40; 'ide': 0.40; 'something': 0.40;
'want': 0.40; 'method': 0.61; 'skip:b 10': 0.63; 'well': 0.65;
'less': 0.65; 'let': 0.66; '100%': 0.66; 'generally': 0.67;
'time,': 0.67; 'right': 0.68; 'and,': 0.69; 'important.': 0.69;
'manually': 0.69; 'global': 0.73; 'skip:f 20': 0.75; 'treat':
0.76; 'unusual': 0.81; 'debugging,': 0.84; 'experiment': 0.84;
'say,': 0.84; 'subject: \n ': 0.84; 'caused': 0.86; 'line,': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1709799816; x=1710404616; darn=python.org;
h=content-transfer-encoding:in-reply-to:from:content-language
:references:to:subject:user-agent:mime-version:date:message-id:from
:to:cc:subject:date:message-id:reply-to;
bh=w6jLZz+G0ETqf2BOO6g37wSDGzFQxST98bjY47wdC9o=;
b=EfVTxMa11uP4TcWsEG9XRPiYUZiH6h2cp9MqgguRv+3Wl2Obf0gP7b2FhuZ+kG2NC5
UnSE9zYgl/e080WhfA5tHzWPQtP6EXbvn/V5xIqnzTaGEz1Zz04zHkjVP825MDLcQpOQ
Ye+0G6X1XKIfiNHv0V4khsPq7Vd/2lddHwkCCpCFsUL6m0cpm/V5suQ5U0ojUnPVa7LY
1k3fFvWddLYGu5geMJrYXNiE0uDdsmxxgMDublq+lNvDpRVKoXw/EebgPdWE01xLNKq/
TVH1nTlQsdhgXIolE5VuY00trLIx11kM3Ms28VO/675S52JQuOr/pNgfJEXGCjUeo2t1
I5Gg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1709799816; x=1710404616;
h=content-transfer-encoding:in-reply-to:from:content-language
:references:to:subject:user-agent:mime-version:date:message-id
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=w6jLZz+G0ETqf2BOO6g37wSDGzFQxST98bjY47wdC9o=;
b=mgmWg4HrPQyswKfTWPTaTC2a/meVzrgEZigAXY0uWf8iUQvjAjIqdhVsK0EXQG75bj
9qPfhgiereKuGKyiM0ttLb7AFn4gcVI2y6gwHBw8lZycMFaH1f+MgDEi3+vy8QM2tnQx
279hxE0WVYSLmfBrWwtPfNA2TxyMTUEt4GpM3ydZEvlKSkWOsdNDpTvQ292jnrNDphsb
DNIDGiBgwcKSACRoCkEY718IaH+l2CQXzRItPxc58fryjNabPJc01A0Kdz6aK6aW8tbG
4Jxz+GMitZARlV5bQOAiDJd4LIIrhiogMSlpe29yLXjJ+cTh0hz5XFZdZUHkN75Frd9Q
5H5A==
X-Gm-Message-State: AOJu0Yx87Tg9MEMnmZz49t0v/uG96Se5iMW346JX+XUXiqzDY+5NrdGw
18PrkAa+drOXgYIu42HBh20JZOAaDSkM2stl5++7X+QQWxUPvWvf/xFKB7Dc
X-Google-Smtp-Source: AGHT+IH27mmp7N6D5JoneeIvXdPRbsjj/Gdv/07FzSNWstITMiw9CcQP081RUxoqm/hCC1+eOOy2hQ==
X-Received: by 2002:a17:906:d287:b0:a45:73b0:bcc3 with SMTP id
ay7-20020a170906d28700b00a4573b0bcc3mr697586ejb.34.1709799815981;
Thu, 07 Mar 2024 00:23:35 -0800 (PST)
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <4Tqsp41DHBznTq9@mail.python.org>
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: <e8fd7bbc-b52a-4a0d-8934-c7c5630cde20@gmail.com>
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>
<da56d0f1-ae1c-4f73-9493-c07f7c6d13c5@DancesWithMice.info>
<4Tqsp41DHBznTq9@mail.python.org>
 by: Jacob Kruger - Thu, 7 Mar 2024 08:23 UTC

Thanks again, all.

I think the python -i scoping2.py would have given me a good beginning
as well - will archive that one for use.

And, to maybe explain how I work - not an excuse at all - but, I am
actually 100% blind, so a lot of the IDE's, or their common
means/methods of interaction don't suit me all the time, which is why I
generally work via programmer's text editor interfaces, or treat
something like VS code as such, but then still prefer to run my code via
command line, using pdb to then play around with forms of debugging, etc.

And, yes, also generally prefer to work via classes, modules, etc. at
runtime, but this was more or less mostly testing, which then caused
confusion/interference on my side...LOL!

Jacob Kruger
+2782 413 4791
"Resistance is futile!...Acceptance is versatile..."

On 2024/03/07 03:55, Grant Edwards via Python-list wrote:
> On 2024-03-07, dn via Python-list <python-list@python.org> wrote:
>
>> 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.
> Unless the code is intended to be used as a module, 'import'ing it into
> the REPL doesn't make sense.
>
> A simple example:
>
> ---------------------------testit.py------------------------------
> x = 'x'
> y = 'y'
> def foo():
> global y
> print("hi")
> x = 'X'
> y = 'Y'
> print(x)
> print(y)
> ------------------------------------------------------------------
>
> The usual method to play with that interactively is
>
> $ python -i testit.py
> >>> x
> 'x'
> >>> y
> 'y'
> >>> foo()
> hi
> X
> Y
> >>> x
> 'x'
> >>> y
> 'Y'
> >>>
>
> As we've seen, doing a 'from testit.py import *' doesn't let you test
> what the OP was trying to test. Doing 'import testit.py' gets you
> closer, but it's a hassle to test code that way. The right thing to do
> is 'python -i <filename>' (or the equivalent button/option in an IDE).
>
> https://docs.python.org/3/tutorial/interpreter.html
>
> If you intended to use testit.py as a module, and wanted to experiment
> with its behavior as a module, then go ahead and import it. But, don't
> do 'from testit.py import *' until
>
> 1. you know how that differs from 'import testit.py'
>
> and
>
> 2. you want to use that difference
>
>

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor