I simply prefer to repeat the property()
as well as you will repeat the @classmethod
decorator when overriding a class method.
While this seems very verbose, at least for Python standards, you may notice:
1) for read only properties, property
can be used as a decorator:
class Foo(object):
@property
def age(self):
return 11
class Bar(Foo):
@property
def age(self):
return 44
2) in Python 2.6, properties grew a pair of methods setter
and deleter
which can be used to apply to general properties the shortcut already available for read-only ones:
class C(object):
@property
def x(self):
return self._x
@x.setter
def x(self, value):
self._x = value
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…