How can I create a dict that sets a flag if it's been modified

Paul Rubin http
Thu Jan 12 04:32:45 EST 2006


sandravandale at yahoo.com writes:
> Still, I'd love to hear how you guys would do it.

Make a subclass of dict, or an object containing a dictionary, that
has a special __setattr__ method that traps updates and sets that
modification flag.  There are contorted ways the caller can avoid
triggering the flag, but Python is not Java and it in general makes no
attempt to protect its objects against hostile code inside the
application.

Your suggestion of using pickle is shaky in my opinion, since pickle's
docs don't guarantee that pickling the same dictionary twice will
return the same pickle both times.  If it happens to work that way,
it's just an implementation accident.



More information about the Python-list mailing list