所以在這裏我有一個問題。假設我有兩個父類。他們都從一個主類繼承。然後,它們都是子類的父類。有沒有辦法找出(比方說,我的父親)的母親類我「具有一個孩子?」我不需要孩子找出哪個媽媽級,我希望父親能夠弄清楚它是媽媽級的。的Python:找出「配偶」類?
我知道這是一個愚蠢的例子,但它是什麼,我必須做到萬無一失的簡化版本。
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'
〜
〜
〜
〜
即使Python是沒有強大到足以找出一個配偶。 – 2012-08-01 01:52:39