In CPython, the builtin-function id(x) returns the memory address of x.
Is it possible to reverse this ?
Something like object_by_memoryadress(id(x)) == x.
Update: The reason I need this is, because I’m using a program with embedded Python. And in this program I can create so called “Nodes” that can communicate with each other, but only with integers, strings, and stuff, but I’d need to “transfer” a list between them (which is not possible the usual way).
I have created a shared library that contains the following code:
compiled it and wrapped it using ctypes:
Now you can exchange python objects through their memory adress within one python process.
But be aware of already garbage collected objects ! The following code will crash the Python interpreter.