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

2009-04-08 Thread Christian Heimes
TP wrote: > If "di" is reliable, it seems a good solution for my initial constraint > which is the impossibility to store anything but strings in my data > structure. 'di' is dangerous and not reliable. When the original object is freed, then the memory address may be used by another Python object

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

2009-04-08 Thread CTO
Correction: the UserString will be dead on the final line. When I typed it in I had a strong reference still hanging around. -- http://mail.python.org/mailman/listinfo/python-list

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

2009-04-08 Thread CTO
> I don't know what is the best: > * using an additional dict and maintaining it It works, but as you say, is somewhat inelegant. > * or using the "di" module proposed by CTO Let me be clear: I am not proposing that you use it. It *does* do what you ask- but what you are asking is, all by itself

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

2009-04-08 Thread TP
MRAB wrote: > You could create a dict with the string as the key and the object as the > value. Thanks. But it implies an additional data structure: a dictionnary. I don't know what is the best: * using an additional dict and maintaining it * or using the "di" module proposed by CTO If "di" is r

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

2009-04-08 Thread CTO
> You could create a dict with the string as the key and the object as the > value. This will create a strong reference to the object, which is (I'm assuming) undesired behavior. -- http://mail.python.org/mailman/listinfo/python-list

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

2009-04-08 Thread Gary Herron
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 exa

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

2009-04-08 Thread MRAB
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 exa

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

2009-04-08 Thread CTO
> 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). can you just use a weakref instead? It is certainly cleaner than trying to store id's, since an id is only guaranteed to be uniq

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

2009-04-08 Thread TP
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 "fo