global variable not seen (bug?)

Michal Vitecek fuf at
Wed Jan 8 18:25:56 CET 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
>        <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 "", line 2, in someFunction
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

More information about the Python-list mailing list