>>> class mytest():
... pass
...
>>> x=mytest()
>>> id(x)
140696428216768
>>> x
<__main__.mytest object at 0x7ff670a001c0>
>>> int(0x7ff670a001c0)
140696428216768
We know that 0x7ff670a001c0
or 140696428216768
is the address of variable x
.
How can get the variable name from address ?
>>> import ctypes
>>> ctypes.cast(140696428216768, ctypes.py_object).value
py_object(<__main__.mytest object at 0x7ff670a001c0>)
>>> ctypes.cast('0x7ff670a001c0', ctypes.py_object).value
Segmentation fault