I am trying to implement Javascript closures in Python 2.7.
Consider the following code:
var = {'upper_scope':None}
def f1():
print var
def f2():
var = {'upper_scope': var}
The first function works fine. The second one fails on its first line:
UnboundLocalError: local variable 'var' referenced before assignment.
I would like to read the value of var from the upper scope and place it inside a local dictionary named var.