Suppose I have Python code:
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()
This script prints "Daughter." Is there a way to ensure that all methods of __init__ class classes are called? One of the methods that I came up with was the following:
class Daughter(Mother, Father): def __init__(self): print("Daughter") for base in type(self).__bases__: base.__init__(self)
This script prints "Daughter", "Mother", "Father". Is there a good way to do this using the super () method or another method?
source share