how to update objects?

Martin von Loewis loewis at informatik.hu-berlin.de
Mon May 29 11:31:16 EDT 2000


noemail at nowhere.hades (Mike Cat) writes:

> I update a class with 'reload (module)'.
> How can I update the instances too?

You'd have to find the instance one-by-one. If you manage to get hold
of them, you can set their __class__ attribute to the new class:

>>> class A:
...   def doit(self):print "old"
... 
>>> a=A()
>>> class A:
...   def doit(self):print "new"
... 
>>> a.doit()
old
>>> a.__class__=A
>>> a.doit()
new

Regards,
Martin




More information about the Python-list mailing list