self-registering objects?
Michael Hudson
mwh21 at cam.ac.uk
Fri Oct 29 18:28:58 EDT 1999
"Ionel Simionescu" <ionel at psy.uva.nl> writes:
> Hi,
>
> I would like objects of a certain class to be able of registering themselves
> in a global dictionary, __register__, possibly upon __init__.
>
> __register__ should contain associatins such as:
>
> { 'ID': <__main__.certain_class instance at ####> }
>
> Unfortunately, the naive:
"the naive" works more often than you'd think in Python (that's one of
the great things about it).
> def __init__(self, etc.):
> global __register__
> self.ID = 'instance1'
> __register__[self.ID] = self
>
> Does NOT work.
>
> The object that I find in the __register__ under the given ID is apparently
> just the bare bones of the class and gets none of the changes incured to the
> instance after registration.
Really? That's odd. Can you post the code that's misbehaving, that's
always much more helpful; what you have above looks to me if it should
work.
> It's is not a problem if I register the object "from outside",
> but I would like to understand what's going on...
So would I... you've stirred my curiosity.
more-code-please-ly y'rs
Michael
More information about the Python-list
mailing list