我有一个使用字段的基类:
class Base(object):
def __init__(self, member):
self.member = member
以及想要将其提升为属性并添加一些行为的派生类:
class Derived(Base):
@property
def member(self):
return super(Derived, self).member
@member.setter
def member(self, value):
print "intercepting setter"
super(Derived, self).member = value
但是,这并没有正确地委托给基类:
>>> d = Derived(0)
intercepting setter
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
d = Derived(0)
File "<pyshell#3>", line 3, in __init__
self.member = 2
File "<pyshell#6>", line 9, in member
super(Derived, self).member = value
AttributeError: 'super' object has no attribute 'member'
我应该怎么做?