co_freevars question

Jeff Epler jepler at unpythonic.net
Tue Apr 20 14:55:38 EDT 2004


co_freevars names variables that come from an enclosing scope that is
not module scope.

def g():
    return y
print g.func_code.co_freevars       # ()

def f():
    y = 3
    def g(): 
        return y
    print g.func_code.co_freevars   # ('y',)
f()

Jeff




More information about the Python-list mailing list