use Userdict for class __dict__
Hans Nowak
hnowak at cuci.nl
Thu Dec 2 16:49:24 EST 1999
On 1 Dec 99, at 14:41, Gang Li wrote:
> 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.
Hmm... assuming that your MyUserDict still uses the dictionary called
'data' internally, you can use that:
Foo.__dict__ = MyUserDict(Foo.__dict__).data
I don't know if it will have the desired result though. =/
--Hans Nowak (zephyrfalcon at hvision.nl)
Homepage: http://fly.to/zephyrfalcon
You call me a masterless man. You are wrong. I am my own master.
More information about the Python-list
mailing list