supponiamo che ho un po 'di codice Python:C'è un modo per usare super() per chiamare il metodo __init__ di ogni classe base in Python?
class Mother:
def __init__(self):
print("Mother")
class Father:
def __init__(self):
print("Father")
class Daughter(Mother, Father):
def __init__(self):
print("Daughter")
super().__init__()
d = Daughter()
Questo script stampa "Figlia". Esiste comunque la garanzia che tutti i metodi __init__ delle classi basi vengano chiamati? Un metodo che mi è venuta per fare questo è stato:
class Daughter(Mother, Father):
def __init__(self):
print("Daughter")
for base in type(self).__bases__:
base.__init__(self)
Questo script stampa "Figlia", "Madre", "Padre". C'è un modo carino per farlo usando super() o un altro metodo?