我有一个具有以下类结构的项目:
class A(object):
elems = [1, 2, 3]
class B(A):
pass
class C(B):
elems = [20, 100]
class D(B):
elems = [4, 5]
目前,Python 的默认继承行为是elems
在每个后续属性声明中覆盖该属性,例如:
A.elems == [1, 2, 3]
B.elems == [1, 2, 3]
C.elems == [20, 100]
D.elems == [4, 5]
我希望能够访问这些值的附加列表。换句话说,我希望能够检索以下列表:
A.collated() == [1, 2, 3]
B.collated() == [1, 2, 3]
C.collated() == [1, 2, 3, 20, 100]
D.collated() == [1, 2, 3, 4, 5]
我不知道该怎么做。任何帮助将不胜感激。
在此先感谢,
-B