00001 """ 00002 properties only work when have a new style base class 00003 ie they do not work when using 00004 00005 class Dummy: 00006 blah 00007 00008 """ 00009 class Dummy(object): 00010 def __init__(self): 00011 self._A = "a" 00012 self._B = "b" 00013 00014 def GetA(self): 00015 print "GetA" 00016 return self._A 00017 def GetB(self): 00018 print "GetB" 00019 return self._B 00020 00021 def SetA(self,v ): 00022 print "SetA" 00023 self._A = v 00024 def SetB(self,v ): 00025 print "SetB" 00026 self._B = v 00027 00028 def state(self): 00029 return "self._A:%s self._B:%s self.a:%s self.b:%s " % ( self._A, self._B , getattr(self,"a",None), getattr(self,"b",None) ) 00030 00031 00032 00033 if __name__=='__main__': 00034 d = Dummy() 00035 d.SetA( "1 set a") 00036 d.SetB( "1 set b") 00037 00038 print d.state() 00039 00040 kls = Dummy 00041 kls.a = property( kls.GetA, kls.SetA ) 00042 00043 print d.state() 00044 00045