Dispatch with multiple inheritance

looping kadeko at gmail.com
Wed Jul 19 02:25:59 EDT 2006


Michael J. Fromberger wrote:
>
> Is there a better (i.e., more elegant) way to handle the case marked
> (**) above?
>

You have to call super in each method __init__, if you don't, the call
chain break before the end:

class A (object):
    def __init__(self):
        super(A, self).__init__()
        print "cons A"

class B (object):
    def __init__(self):
        super(B, self).__init__()
        print "cons B"

class C (A):
    def __init__(self):
        super(C, self).__init__()
        print "cons C"

class D (B):
    def __init__(self):
        super(D, self).__init__()
        print "cons D"

class E (C, D):
    def __init__(self):
        super(E, self).__init__()  # calls C constructor
        print "cons E"




More information about the Python-list mailing list