Unbound Local error? How?
Hari Sekhon
sekhon.hari at googlemail.com
Tue Jun 27 10:31:21 EDT 2006
I've got some code as follows:
import re
re_regexname = re.compile('abc')
.....
..... various function defs
.....
def func1():
...
func2()
...
def func2():
if re_regexname.match('abc'):
<do something>
if __name__ == '__main__':
func1()
but this returns the Traceback:
UnboundLocalError: local variable 're_regexname' referenced before
assignment
How?
It was declared in the zero level indentation near the top of the
script! I don't understand this, isn't a function supposed to be able to
reference stuff in the containing function or the top level?
More information about the Python-list
mailing list