instance creatiion as an "event"
Aahz
aahz at pythoncraft.com
Tue Apr 15 08:17:31 EDT 2003
In article <mailman.1050117319.5102.python-list at python.org>,
Steven Taschuk <staschuk at telusplanet.net> wrote:
>Quoth Simon Burton:
>> On Fri, 11 Apr 2003 17:15:32 -0400, Arthur wrote:
>>>
>>> The only thing I seem to be missing is some kind of "hook" to trigger a
>>> general update cycle of all existing class instances upon the creation
>>> of a new class instance at the interactive prompt
>>
>> class Member:
>> members = []
>> def __init__(self):
>> for m in Member.members:
>> m.notify(self)
>> Member.members.append(self)
>> def notify(self,other):
>> print self,"a new member:",other
>
>Though you will probably want to use weak references in
>Member.members, unless you intend that all instances of the class
>live as long as the class does.
Blech. It's essentially impossible to delete a class as long as
instances of it exist.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
This is Python. We don't care much about theory, except where it intersects
with useful practice. --Aahz, c.l.py, 2/4/2002
More information about the Python-list
mailing list