我有这个
#!/usr/bin/env python
import math
class myclass(object):
def __init__(self,radius):
self.radius = radius
@property
def area(self):
print myclass.area, type(myclass.area)
return math.pi * ( self.radius ** 2)
@area.setter
def area(self,value):
print myclass.area, type(myclass.area)
pass
@area.deleter
def area(self):
print myclass.area, type(myclass.area)
del myclass.area
if __name__ == '__main__':
c = myclass(5.4)
c.area
c.area = 65
del c.area
这给出了:
$ ./propertytest.py
<property object at 0x7ff0426ac0a8> <type 'property'>
<property object at 0x7ff0426ac0a8> <type 'property'>
<property object at 0x7ff0426ac0a8> <type 'property'>
问题:
查看属性对象area
的访问方式:c.area
. area
出现在点运算符的右侧。属性对象使用哪种特殊方法将类实例对象与正确的实例方法绑定并计算结果?属性如何运作?