>>> main() >>> for h in vt.history: >>> print h (0, 'target_trackstate.py', 6, '__init__') (1, 'target_trackstate.py', 9, 'advance') (2, 'target_trackstate.py', 9, 'advance') (3, 'target_trackstate.py', 9, 'advance') import sys, inspect class ValueTracker(object): # a descriptor def __init__(self, tgt_cls, aname): self.attrname = aname self.history = [] setattr(tgt_cls, aname, self) def __get__(self, obj, type=None): return instance.__dict__[self.attrname] def __set__(self, obj, value): instance.__dict__[self.attrname] = value finfo = inspect.getframeinfo(sys._getframe(1) ) self.history.append((value, finfo.filename, finfo.lineno, finfo.function)) Example 7: Tracking Changes in a Value The Magic of Metaprogramming file:///home/jrush/notes/presentations/MyTalks/talk-Magic... 58 of 59 03/15/2013 10:26 AM