4 ms·
Not something I would put into production, but had a fun application of this on a side project. I had the `id` of a function (but not the function object itself
by aggerdom 8y ago
Not something I would put into production, but had a fun application of this on a side project. I had the `id` of a function (but not the function object itself) and needed to recover the function. In CPython, `id` of a function corresponds to it's memory address (not sure if that can be overridden). By casting the id to a PyObject, I was able to recover the original.
func = ctypes.cast(int(address), ctypes.py_object).value
Was kinda cool actually seeing that work.