自定义dict
class Test1(dict): def __init__(self): self.update() self.load() def update(self): print 'update 执行' def load(self): k = 'key' v = 'value' dict.__setitem__(self,k,v) def __setitem__(self, key, value): print '__setitem__ 执行' self.__dict__[key] = value return dict.__setitem__(self,'k1','v1') t = Test1() t['a'] = 'b' print t.__dict__ # {'a':'b'} print t.get('key') # value print t.get('a') # Noneprint t.get('k1') # v1