global variable not seen (bug?)

Michal Vitecek fuf at mageo.cz
Wed Jan 8 10:51:01 EST 2003


 hello everyone,

 i've encountered a strange problem with accessing a global variable
 from imported module. the imported module (file imported.py) contains:
 
---imported.py start---
 def someFunction():
    global GLOBAL_VARIABLE

    print GLOBAL_VARIABLE
---imported.py end---

 and now the session copy:

---session start---
Python 2.2.1 (#4, Sep  4 2002, 13:43:54) 
[GCC 2.95.3 20010315 (release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> GLOBAL_VARIABLE = 'some value'
>>> from imported import *
>>> dir()
['GLOBAL_VARIABLE', '__builtins__', '__doc__', '__name__', 'someFunction']
>>> someFunction()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "imported.py", line 4, in someFunction
    print GLOBAL_VARIABLE
NameError: global name 'GLOBAL_VARIABLE' is not defined
>>> 
---session end---

 what's the problem here? it seems to me like this is a bug in python.

    thanks for any responses,
-- 
		fuf		(fuf at mageo.cz)





More information about the Python-list mailing list