def __setattr__(self, item, value):
"""Maps attributes to values.
Only if initialized and there *isn't* an attribute with this name
"""
# Note: this allows normal attributes access in the __init__ method
super_setattr = super(AttrDict, self).__setattr__
if '_AttrDict__attr2item' not in self.__dict__: # slot??
return super_setattr(item, value)
if item in dir(self): # any normal attributes are handled normally
return super_setattr(item, value)
return self.__setitem__(item, value)
评论列表
文章目录