[Q] Bug in Python?

Daehyok Shin DSHIN at nc.rr.com
Thu Mar 15 01:15:53 EST 2001


Recently, I met a strange behavior of Python 6.1.
When I tried the following module,
I got an error message in "print var":
    UnboundLocalError: var

But, when I changed "var=None" to "pass",
the error message was gone and I got an expected result:--printing None and
None.
What happens here? Is this a bug in Python or I missed something?

############# test.py ###############
var = None

def a():
     print var #UnboundLocalError
     if var != None:
          var = None  # >> pass

def b():
     print var
     a()

b()
#################################

--
Daehyok Shin (Peter)
Terrestrial Hydrological Ecosystem Modelers
Geography Department
UNC-CH





More information about the Python-list mailing list