我不确定我是否正确写了这个词,但有没有办法让一个班级变量"知道它的父母"?也许是一种重写__ new __的方式?因为从未创建过A的实例,所以我无法想到某种方式。例如,见下文:
class B(object):
def return_parent_class(self):
#here's where i'd like to see what the class is
return []
class A(object):
thingie = B()
class C(A):
value = 1
class D(A):
value = 2
C.thingie.return_parent_class().value # would like to equal 1
D.thingie.return_parent_class().value # would like to equal 2