global variable not seen (bug?)

Adonis deltapigz at telocity.com
Wed Jan 8 18:05:03 CET 2003


not a bug.
you must assign a value to GLOBAL_VARIABLE

def someFunction():
    global GLOBAL_VARIABLE
    GLOBAL_VARIABLE = 1
    print GLOBAL_VARIABLE

hope this helps.

Adonis

"Michal Vitecek" <fuf at mageo.cz> wrote in message
news:mailman.1042041138.4444.python-list at python.org...
> 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