środa, 8 sierpnia 2012
python traced class
With metaclass programming in python you can easily created a class tracing all updates to its attributes:
All objects using Traced metaclass are able to tell you which attributes have been changed. To get list of updated attributes (or keys when using TracedDict or indexes in case of TracedList) just call updated member function.
There is only one shortage: attributes defined and set inside __init__ (real instance attributes like instanceAttribute in TracedTest class) will be put into updated list when calling constructor. To avoid this behavior and trace changed during lifetime of object you need at call at ther very last line in constructor self.updated( reset = True ) (or uncomment last line in above example).
Subskrybuj:
Komentarze do posta (Atom)
Brak komentarzy:
Prześlij komentarz