所以我有个问题。假设我有两个父类。它们都继承自主类。然后它们都是子类的父类。有没有办法搞清楚(比如说我是父亲)我“和哪个母亲班生孩子”呢我不需要孩子知道是哪个母亲班,我希望父亲能够知道是哪个母亲班。你知道吗
我知道这是一个愚蠢的例子,但这只是我在其他地方必须做的一个简化版本。你知道吗
class Master(object):
def __init__(self):
self.troll()
self.trell()
class Mother1(Master):
def troll(self):
print 'troll1'
class Mother2(Master):
def troll(self):
print 'troll2'
class Father(Master):
def trell(self):
print 'trell'
print self.figure_out_spouse_class()
class Child1(Mother1, Father):
pass
class Child2(Mother2, Father):
pass
c = Child1() #should print 'Mother1'
c = Child2() #should print 'Mother2'
~
~
~
~
您可以查看子对象类的
__bases__
,例如您可以使用
__bases__
:(如果有多个“配偶”类别,则返回所有“配偶”类别的名称)。你知道吗
相关问题 更多 >
编程相关推荐