How do I get an object from the id()-identifier?

Malcolm Tredinnick malcolm at
Thu May 17 04:28:35 EDT 2001

On Thu, May 17, 2001 at 10:51:30AM +0300, Mats Sjoberg wrote:
> I know that I can get a unique identifier (usually the memory 
> address) of a python object with the id() function, but how do
> I get the object back if I only have this identifier? (This will
> all of course happen in the same session, otherwise the objects
> will already be removed by the garbage collection...)

I'm tempted to say "you can't", but I'll be more accurate and say "I
don't know how you can do it".

More interesting to me is why you might need to do this? Since
everything is a reference in Python, keeping a variable that contains a
reference to an object (any object!) is no more expensive than keep a
variable that contains a reference to a number representing the objects
id. And, as you say, you're within the same session, so why can't you
keep a reference?


The colder the x-ray table, the more of your body is required on it.

More information about the Python-list mailing list