# propertyModifier.py
class Ball:
def __init__(self, attr):
if attr <= 0:
raise ValueError('必須是正數')
self.attr = attr
def otherMethod(self):
print ("stayhigh method.")
@property
def myProperty(self):
print ("stayhigh method.")
@myProperty.setter
def myProperty(self,attr):
self.attr = attr
@myProperty.deleter
def myProperty(self):
del self.attr
b = Ball(1)
b.myProperty #myProperty關連到->Ball的屬性attr的get,set,del
沒有留言:
張貼留言