reverse function of id()

Brian Lloyd Brian at digicool.com
Wed Oct 13 09:15:07 EDT 1999


> Is there a way to get the Python Object whose id is X...
> 
> ex :
> 
> myObject=MyClass()
> myId=id(myObject)
> myObject=None # See note
> ....
> <far away>
> ....
> myObject=FindObjectFromId(myID)
> ....
> 
> (Note : Please don't care about the ref count problems in my 
> example, I know
> that here myObject is released immediatly)
> 
> Thx !

This seems to be fraught with peril - in fact your example
demostrates exactly why :^) While I assume it would be easy
enough to write an extension module with a C method that 
takes an id and makes a PyObject pointer out of it and returns
it to Python, the example above demonstrates why this would
be dangerous. After you set myObject=None, your myID is now
meaningless, and you'd get a wild pointer back from the
FindObjectFromId method.

Just my 0.02...

Brian Lloyd        brian at digicool.com
Software Engineer  540.371.6909              
Digital Creations  http://www.digicool.com 





More information about the Python-list mailing list