[Tutor] id()

Remco Gerlich scarblac@pino.selwerd.nl
Thu, 26 Apr 2001 23:59:48 +0200


On  0, Stephen Aichele <aichele@mindspring.com> wrote:
> I have a question regarding the use of id(): basically, I'd like to find a
> way to reverse this process- in otherwords, is there a way to access a
> specific instance's attributes from the id # alone?

No.

> I need to do this because in my app, I may have several instances of the
> same class up concurrently - all with the same variable name...  (I'm using
> wxPython) - I know that by reusing the variable name, I won't have access to
> any but the last instance created; however, I'm wondering if the previous
> instance IDs will still exist and if so, how to use them to access previous
> instances/windows...

An object ceases to exist when the last reference to it is gone.

So if nothing else keeps a reference to your class instance, it will be gone
the moment you assign something else to the variable.

If something else does keep a reference (see, you've attached it to the GUI
or so) there may be a way to get it back from there, who knows.

> sorry to be so confusing (and confused), but if anyone has an idea of my
> problem and how to deal with it, I'd love to hear it.

Um, don't do that then? :)

You could keep an index to them. Append them to a list when you create them,
or something like that. Then you can keep referring to them through the list.

Apparently you do keep the objects' id(). Why don't you keep the object
itself there instead?

Without more information about what you're doing I don't think I can give
more advice.

Time to sleep now, then I'll be gone for two days...

-- 
Remco Gerlich