how to get back an object from its id() value

MRAB google at mrabarnett.plus.com
Wed Apr 8 12:05:30 EDT 2009


TP wrote:
> Hi everybody,
> 
> I have a data structure (a tree) that has one constraint: I can only store
> strings in this data structure.
> 
> To know if an object foo already exists in memory, I store "str(id(foo))" in
> the data structure.
> OK.
> 
> But how do I get a usable reference from the id value?
> For example, if "foo" has a method "bar()", how can I call "foo.bar()"
> from "str(id(foo))" (say, 149466208).
> 
You could create a dict with the string as the key and the object as the
value.



More information about the Python-list mailing list