global variable not seen (bug?)
fuf at mageo.cz
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
this doesn't help:
>>> from imported import *
>>> GLOBAL_VARIABLE="some value"
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "imported.py", line 2, in someFunction
NameError: global name 'GLOBAL_VARIABLE' is not defined
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