global variable not seen (bug?)

Michal Vitecek fuf at mageo.cz
Wed Jan 8 12:25:56 EST 2003


Mike Meyer wrote:
>The global statement doesn't declare a variable, it tells the
>interpreter to look in the global namespace for the variable. Since it
>isn't there, the name is going to be undefined. Try doing
>"GLOBAL_VARIABLE = 1" in your interpreter before you infoke
>someFunction().
>
>        <mike

 this doesn't help:

---session start---
>>> from imported import *
>>> GLOBAL_VARIABLE="some value"
>>> someFunction()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "imported.py", line 2, in someFunction
    print GLOBAL_VARIABLE
NameError: global name 'GLOBAL_VARIABLE' is not defined
>>> 
---session end---

 i must say that this behaviour is pretty strange (non-intuitive at
 least). why is it that the function looks for that variable in the
 scope of its module? wouldn't that be more intuitive if it looked for
 the variable in the current global scope?

-- 
		fuf		(fuf at mageo.cz)





More information about the Python-list mailing list