use Userdict for class __dict__

Gang Li gang.li at compuware.com
Wed Dec 1 16:41:31 EST 1999


In order to monitor access of class attributes, I tried to replace class
__dict__ with UserDict.

class Foo: pass

class MyUserDict(UserDict.UserDict):
    def __getitem__(self, name):
        ......

Foo.__dict__ = MyUserDict(Foo.__dict__)

But python bit me with:
    TypeError: __dict__ must be a dictionary object

How can I avoid this kind error.






More information about the Python-list mailing list