Thursday 8 August 2013

Variable scope for nested functions in python

Variable scope for nested functions in python

I have a demo example:
def outer(func):
def inner(foo):
func(arg_inner,foo)
return inner
def third_party(arg1,arg2):
#do something
final = outer(third_party)
final(3)
I wonder how comes the inner function knows the value of func while being
called. How the scope of inner function and outer are connected?

No comments:

Post a Comment