This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: global variable: multiple id()-addresses
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: fschaef, georg.brandl
Priority: normal Keywords:

Created on 2006-08-17 18:37 by fschaef, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
python-bug-or-feature.tgz fschaef, 2006-08-17 18:37 Test Files for Global-Shadow-Twin-Bug
Messages (2)
msg29541 - (view) Author: Frank R. Schaefer (fschaef) Date: 2006-08-17 18:37
The **attachment** contains an example where one single
global variable appears at two different positions
when applying the 'id(...)' function.
The following files are attached:

core.py:  contains the definition of the global
          variable, two example functions, and 
          a minimal class definition.

test.py:  a test program displaying that the global
          variable in core.py has two addresses.

result.txt: the output of the test.py procedure.

In practical this means that a variable
'my_module.global_var' may refer to two 
different objects!
msg29542 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-08-17 18:54
Logged In: YES 
user_id=849994

In not_so_simple(), you *reassign* global_var. That means
that it is bound to a different object afterwards.

The name "global_var" you imported into the test module,
however, is bound to the original global_var object, and
this binding will not change. If that's not what you want,
you'll have to do "import core" and refer to "core.global_var".

Additionally, let me point out that using "global" to
declare a name as global in a function that does not
reassign that name is unnecessary.

Closing as Invalid.
History
Date User Action Args
2022-04-11 14:56:19adminsetgithub: 43847
2006-08-17 18:37:11fschaefcreate