UnboundLocalError: local variable part 2

Daniel insaney at ufl.edu
Mon Jun 3 13:03:57 EDT 2002


That last example was a bit too contrived... instead of blah='abc',
blah is actually a list and i'm appending and popping elements so
func1 actually truly does affect the global blah.  So a better example
of the logic is:

def func1():
   blah.pop()

def func2():
   print blah
   blah.pop()

def main():
   func1()
   try:
      func2()
   except:
      pass
   print blah

blah=[1,2,3]
main()

except instead of:
[1, 2]
[1]

it's getting:
[1, 2]
(trap the UnboundLocalError)
[1, 2]
 
I've looked through and cannot find anything that vi might have put in
that is throwing the python interpreter off.

Any thoughts on what might cause this behavior?
Thanks,
Daniel



More information about the Python-list mailing list