class TargetWrapper(d ict):
def __init__(self, **kwargs):
dict.__init__(s elf, kwargs)
__getattr__ = dict.__getitem_ _
__setattr__ = dict.__setitem_ _
__delattr__ = dict.__delitem_ _
then
tw = TargetWrapper()
tw.a = "spam" # ok
del tw.a # ok
tw.b = "egg"
print tw.b
last line give me an
AttributeError: 'TargetWrapper' object has no attribute 'b'
if i define
def __getitem__(sel f, name):
return dict.__getitem_ _(self, name)
__getattr__ = __getitem__
then the accessing the b attribute is ok. what's wrong ?