global variable not seen (bug?)

Skip Montanaro skip at pobox.com
Wed Jan 8 12:03:38 EST 2003


    Michal> ---imported.py start---
    Michal>  def someFunction():
    Michal>     global GLOBAL_VARIABLE

    Michal>     print GLOBAL_VARIABLE
    Michal> ---imported.py end---

Somebody still has to actually assign a value to that name.  All the global
declaration does is tell the system that if you assign a value to the
variable to put it in the global scope of the module, not the local scope
(the function).  This would work:

    GLOBAL_VARIABLE = None
    def someFunction():
        print GLOBAL_VARIABLE

Skip





More information about the Python-list mailing list