In Python 3, you can define x as nonlocal in f2.
In Python 2, you cannot directly assign f1 x to f2. However, you can read its value and gain access to your members. So this could be a workaround:
def f1(): x = [1] def f2(): x[0] = 2 f2() print x[0] f1()
source share