Creating an object that can track when its attributes are modified

88888 Dihedral dihedral88888 at googlemail.com
Wed Mar 6 22:07:40 CET 2013


Ben Sizer於 2013年3月7日星期四UTC+8上午12時56分09秒寫道:
> On Wednesday, 6 March 2013 16:22:56 UTC, Chris Angelico  wrote:
> 
> > 
> 
> > Effectively, you would need to have a
> 
> > subclass of list/dict/tuple/whatever that can respond to the change. 
> 
> 
> 
> This is certainly something I'd be interested in having, but I guess that would be fragile since the user would have the burden of having to remember to use those types.
> 
> 
> 
> > What's the goal of this class? Can you achieve the same thing by
> 
> > using, perhaps, a before-and-after snapshot of a JSON-encoded form of
> 
> > the object?
> 
> > 
> 
> 
> 
> I need to be able to perform complex operations on the object that may modify several properties, and then gather the properties at the end as an efficient way to see what has changed and to store those changes. Any comparison of before-and-after snapshots could work in theory, but in practice it could be expensive to produce the snapshots on larger objects and probably expensive to calculate the differences that way too. Performance is important so I would probably just go for an explicit function call to mark an attribute as having been modified rather than trying to do a diff like that. (It wouldn't work for rollbacks, but I can accept that.)
> 
> 
> 
> -- 
> 
> Ben Sizer
Please hook a stack implemented as a list in python  to every property 
of the object  that you want to track down.





More information about the Python-list mailing list