Monday, July 11, 2005


OOmadness: "
EditObj includes an observation framework for Python object. Add modification-callback to any Python object !
Your callback function will be called every time the object is changed ! Really magic :-D

Observe is pure-Python and supports both old-style and new-style class instances, as well as lists and dictionaries.


>>> from editobj.observe import *
>>> start_observing()
>>> class C: pass
>>> c = C()
>>> def listener(obj, type, new, old):
... if type is object:
... for (attr, newvalue, oldvalue) in diffdict(new, old):
... print 'c.%s was %s, is now %s' % (attr, oldvalue, newvalue)
>>> observe(c, listener)
>>> c.x = 1
c.x was None, is now 1"