How to get the closure environment in Python?

Jin Li lijin.abc at gmail.com
Thu Apr 28 12:23:44 EDT 2016


Hi all,

I want to get the closure environment in Python. As in the following example:

def func1():
        x = 10
        def func2():
                return 0

        return func2

f=func1()
print f()


How could I get the variable `x` in the environment of `func2()`? i.e. `f()`.

Best regards,
Jin



More information about the Python-list mailing list