using super() to call two parent classes __init__() method

Evan Klitzke evan at yelp.com
Sat Aug 18 01:19:06 EDT 2007


On 8/16/07, 7stud <bbxx789_05ss at yahoo.com> wrote:
> When I run the following code and call super() in the Base class's
> __init__ () method,  only one Parent's __init__() method is called.

As the other posters have mentioned, each class needs to make a call
to super. This is because the super call doesn't really call the
parent class' method, it actually calls the next method in the MRO.
The MRO in this case will be Base -> Parent1 -> Parent2 -> object. You
can read the details of Python's MRO here
http://www.python.org/download/releases/2.3/mro/

-- 
Evan Klitzke <evan at yelp.com>



More information about the Python-list mailing list