multiple inheritance super()

km km at mrna.tn.nic.in
Wed Jul 27 03:26:50 EDT 2005


Hi peter,

ya got it working :-) now i understand mro better.

thanks,
KM
-------------------------------------------------------------
On Tue, Jul 26, 2005 at 04:09:55PM -0400, Peter Hansen wrote:
> km wrote:
> > Hi all,
> > 
> > In the following code why am i not able to access class A's object attribute - 'a' ? I wishto extent  class D with all the attributes of its base classes. how do i do that ?
> > 
> > thanks in advance for enlightment ... 
> > 
> > here's the snippet 
> > 
> > #!/usr/bin/python
> > 
> > class A(object):
> >     def __init__(self):
> >         self.a = 1
> >         
> > class B(object):
> >     def __init__(self):
> >         self.b = 2
> > 
> > class C(object):
> >     def __init__(self):
> >        self.c = 3
> >        
> > class D(B, A, C):
> >     def __init__(self):
> >         self.d = 4
> >         super(D, self).__init__()
> 
> Each class should do a similar super() call, with the appropriate name 
> substitutions.
> 
> Calls to __init__ must be made explicitly in subclasses, including in 
> the case of multiple inheritance.
> 
> Also note that often (usually) you would like the __init__ call to come 
> *before* other location initializations, and it's the safest thing to do 
> unless you have clear reasons to the contrary.
> 
> -Peter
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list