reverse function of id()

M.-A. Lemburg mal at lemburg.com
Thu Oct 14 05:17:20 EDT 1999


Olivier Deckmyn wrote:
> 
> Hi !
> 
> 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)

The next version of mxTools will have a function for doing this:

sys.makeref(id) 
         Provided that id is a valid address of a Python object
         (id(object) returns this address), this function returns
         a new reference to it. Only objects that are "alive" can be
         referenced this way, ones with zero reference count cause
         an exception to be raised. 

         You can use this function to reaccess objects lost during
         garbage collection. 

         USE WITH CARE: this is an expert-only function since it
         can cause instant core dumps and many other strange
         things -- even ruin your system if you don't know what
         you're doing ! 

         SECURITY WARNING: This function can provide you
         with access to objects that are otherwise not visible, e.g.
         in restricted mode, and thus be a potential security hole. 

I hope that's enough warnings about what this beast can accomplish ;-)

-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                    78 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/





More information about the Python-list mailing list