<p>如何更新x.test以使值从继承返回?你知道吗</p>
<p>所以我想要x.test返回['test from B'','test from C']</p>
<pre><code>class A()
def __init__(self)
self.test = []
return
def coolThings(self):
# do cool things here and print the new self.test
print self.test
class B(A)
def __init__(self)
A.__init__(self)
return
def doSomething(self)
self.test.append('test from B')
class C(A)
def __init__(self)
A.__init__(self)
return
def doAnotherthing(self)
self.test.append('test from C')
--
In [575] x = A()
In [576] y = B()
In [577] z = c()
In [582] y.doSomething()
In [583] z.doAnotherthing()
In [584] x.test
Out[584] []
In [585] y.test
Out[585] ['test B']
In [586] z.test
Out[586] ['test C']
x.coolThings()
??
</code></pre>
<p>那么,如何更新x.test,使其具有['test from B'','test from C']</p>
<p>但我又怎么能坚持呢自检在所有的遗产中?因此,如果我在y.doSomething()之后调用z.test,我希望得到['testfrom B']</p>
<p>敬礼</p>