Daniel Cer wrote: > Why not just inherit from dict? That seems to work. > > >>> class M(dict): > ... def __getitem__(self,key): > ... return 42 > ... def __setitem__(self,key,value): > ... pass > ... > >>> class C(object): > ... pass > ... > >>> c = C() > >>> c.__dict__ = M() > >>> c.__dict__['x'] > 42 >
Didn't test this very much, did you? >>> c.x Traceback (most recent call last): File "<pyshell#23>", line 1, in -toplevel- c.x AttributeError: 'C' object has no attribute 'x' Or even: >>> c = C() >>> c.__dict__ = M({'x': 1}) >>> c.x 1 >>> c.__dict__['x'] 42 >>> -- http://mail.python.org/mailman/listinfo/python-list