Mam problem. Załóżmy, że mam 2 klasy nadrzędne. Obaj dziedziczą z klasy mistrzowskiej. Następnie obie klasy są rodzicami klasy dziecka. Czy istnieje sposób, aby dowiedzieć się (powiedzmy, że jestem Ojcem), z której klasy matki "mam dziecko"? Nie potrzebuję dziecka, aby dowiedzieć się, która klasa matek, chcę, aby Ojciec mógł dowiedzieć się, która jest klasa matki.Python: Wyobraź sobie klasę "Współmałżonka"?
Wiem, że to głupi przykład, ale jest to uproszczona wersja tego, co muszę zrobić gdzie indziej.
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'
~
~
~
~
Nawet Python nie jest wystarczająco silne, aby dowiedzieć się małżonka. –