property
property([fget[, fset[, fdel[, doc]]]]) => descriptor
Returns a property descriptor for new-style classes (classes that derive from object).
fget is a function for getting an attribute value, likewise fset is a function for setting, and fdel a function for deleting, an attribute. Typical use is to define a managed attribute x:
class C(object):
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.")
o = C()
value = o.x # calls getx
o.x = value # calls setx
del o.x # calls delx
New in version 2.2.
last updated 3 years ago by effbot #

could mention the @property shortcut for readonly attributes here:
turns the "x" method into a "getter" for a read-only attribute with the same name.
Note that this syntax also works for old-style classes, but the resulting attribute isn't read-only. If you assign to the attribute, you'll overwrite the property descriptor.
effbot 3 years ago #