>>> def bar():
abc = 0
def run():
global abc
abc += 1
print abc
return run
>>> ccc = bar()
>>> ccc()
Traceback (most recent call last):
File "<pyshell#52>", line 1, in <module>
ccc()
File "<pyshell#50>", line 5, in run
abc += 1
NameError: global name 'abc' is not defined
as shown in the code, variable 'abc' is defined in function 'bar', a function defined in 'bar' want to access 'abc', I tried to use global declaration before use, but it seem the inner function 'run' only search 'abc' in the outer most namespace. so, how to access 'abc' in function 'run'?