Created
November 19, 2012 20:44
-
-
Save kurtbrose/4113750 to your computer and use it in GitHub Desktop.
nonlocal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def foo(): | |
... a = 2 | |
... def bar(): | |
... print a | |
... return bar | |
... | |
>>> foo().func_closure | |
(<cell at 0x02515FF0: int object at 0x023AA6CC>,) | |
>>> foo().func_closure[0] | |
<cell at 0x02589ED0: int object at 0x023AA6CC> | |
>>> type(foo().func_closure[0]) | |
<type 'cell'> | |
>>> b = foo() | |
>>> b() | |
2 | |
>>> import ctypes | |
>>> ctypes.pythonapi | |
>>> ctypes.pythonapi.PyCell_Set(id(b.func_closure[0]), id(3)) | |
0 | |
>>> b() | |
3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment