标签:
- property(fget=None, fset=None, fdel=None, doc=None)
Return a property attribute.
fget is a function for getting an attribute value, likewise fset is a function for setting, and fdel a function for del’ing, an attribute. Typical use is to define a managed attribute x:
class C: def __init__(self): self._x = None def getx(self): return self._x def setx(self, value): self._x = value def delx(self): del self._x x = property(getx, setx, delx, "I‘m the ‘x‘ property.")
If then c is an instance of C, c.x will invoke the getter, c.x = value will invoke the setter and del c.x the deleter.
property的用法是为你的类设置一个属性值。第一个参数设定获取属性值的方法,第二个参数设定设置这个属性值的方法,第三个参数设定删除这个属性值的方法,第四个参数是文档。c.x会调用第一个参数的方法,c.x = value 调用第二个方法,del c.x调用第三个方法。这样
标签:
原文地址:http://www.cnblogs.com/Blaxon/p/4611034.html