Anybody still here for the holidays?

Wondering if any Python gurus can explain why super works like this:

class A(object):
        def __init__(self):
                print 'A instantiated'
                self.important = 'a'

class B(object):
        def __init__(self):
                print 'B instantiated'
                self.important = 'b'
                self.bIsImportant = 'too'
                pass


class C(A, B):
        def __init__(self):
                super(C, self).__init__()
                super(A, self).__init__()
                pass

c = C()


I would like to trigger the __init__ methods on both classes that C is
inheriting. The first call to:
super(C, self).__init__()

runs the init from the first class listed in the inheritance, 'A'. I'd
really like the second class inherited, 'B', to also run its init, so
after goofing around awhile I stumbled upon the second call to:
super(A,self).__init__()

I'm not sure why setting 'A' as the type in this super called got it
to call the init of the second class, 'B'.

First, should I not even be doing this? Trying to run both inherited
class' inits?
Second, if it is legitimate, why does the syntax 'super([first
inherited class], self).__init__()' call the second inherited classes
init?

Reason I ask is that I'm trying to duplicate this functionality in a
more complicated setup in my code base and I cannot for the life of me
get the second inherited class to run its init like it is here, so I
suspect I stumbled upon a quirky result and I am trying to understand
what is happening so I can get my final goal of actually running both
inits from both inherited classes.

Thanks ahead of time, and good holidays to ya,

-jason

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to