trapping dict alterations in a class

Michael Esveldt dante at oz.net
Sun Apr 16 23:36:57 CEST 2000


I want to be able to do for a dictionary in a given class what 
__setattr__ does for variable binding.

class foo:
    def __setattr__(self, name, value):
        print name, value
        self.__dict__[name] = value
bar = foo()
bar.quux = 1
bar.baz = {"key":"value"}

The above obviously prints "quux 1" and then "baz {'key':'value'}". But 
what if I want to trap further alterations to the foo.baz dictionary? Is 
this possible?

thanks,
Michael
_______________________________________________________________
dante at oz.net - Michael Esveldt - #FightThePower on Openprojects



More information about the Python-list mailing list