Exemplo n.º 1
0
 def __getitem__(self, key):
     print("__getitem__() is called ")
     attrName = Utils.addMemberPrefix(key)
     #if self.__dict__.has_key(attrName):     # AttributeError: 'dict' object has no attribute 'has_key'
     #    return self.__dict__[attrName]
     return self.__dict__[attrName]
     
     return None
Exemplo n.º 2
0
 def __getattr__(self, name):
     print("__getattr__() is called ")  
     attrName = Utils.addMemberPrefix(name)
     #if self.__dict__.has_key(attrName):      # __dict__ 没有 has_key 属性
     #    return self.__dict__[attrName]
     #else:
     #    return None
     # 这种方法是可以的
     for key in self.__dict__:
         if key == attrName:
             return self.__dict__[attrName]
     
     return None
Exemplo n.º 3
0
 def __setattr__(self, name, value):
     print("__setattr__() is called ")
     
     attrName = Utils.addMemberPrefix(name)
     # 这种方法可以
     self.__dict__[attrName] = value
Exemplo n.º 4
0
 def __setitem__(self, key, value):
     print("__setitem__() is called ")
     attrName = Utils.addMemberPrefix(key)
     self.__dict__[attrName] = value;
Exemplo n.º 5
0
 def __setattr__(self, name, value):
     attrName = Utils.addMemberPrefix(name)
     self.__dict__[attrName] = value
Exemplo n.º 6
0
 def __getattr__(self, name):
     attrName = Utils.addMemberPrefix(name)
     return self.__dict__[attrName]