UnboundLocalError: local variable 'blah' referenced before assignment
Daniel
insaney at ufl.edu
Mon Jun 3 12:28:47 EDT 2002
I have a strange problem where a global variable is no longer
referenced.
Stripped down, it's something to the effect of:
def func1():
blah='bcd'
def func2():
print blah
blah='cde'
def main():
func1()
print blah
try:
func2()
except:
pass
print blah
blah='abc'
main()
func2 raises an UnboundLocalError: local variable 'blah' referenced
before assignment and the final print is the 'bcd'. This only happens
in one script I'm working on, all the others it seems fine. I'm
working in vi, so I suspect that maybe the problem is a funky
character got thrown in somewhere in that script, and the interpreter
isn't liking that. I did a quick search and all characters of the
file are in string.whitespace, string.letters, string.digits, or
string.punctuation. What characters might cause this to happen, or if
you suspect the problem is something else, any ideas?
Python 2.2 (#1, Feb 11 2002, 09:52:08)
[GCC 2.95.3 20010315 (release)] on linux2
Thanks,
Daniel
More information about the Python-list
mailing list