> Works for me. Each class must call super(...).__init__(). The first arg 

>  >>> class A(object):
>  ...   def __init__(self):
>  ...     print 'A.__init__()'
>  ...     super(A, self).__init__()
>  ...
>  >>> class B(object):
>  ...   def __init__(self):
>  ...     print 'B.__init__()'
>  ...     super(B, self).__init__()
>  ...
>  >>> class C(A, B):
>  ...   def __init__(self):
>  ...     print 'C.__init__()'
>  ...     super(C, self).__init__()
>  ...
>  >>> C()
> C.__init__()
> A.__init__()
> B.__init__()
> <__main__.C object at 0x00A32BB0>

Thats almost exactly what I did but with several extra MI classes 
to test things like diamond lattice etc. BUT I say almost because 
the one thing I didn't do is call super() at the highest level. 'A' 
and 'B' in your case. DUH!

Its obvious when I look at it now but in my mind I was thinking 
they didn't have a superclass, but of course they do - object!

Having said that I still don't like that mechanism since it makes 
the behaviour of the subclass depend on the implementation of 
the superclass. That is, if I choose to create a sub class of 
someone elses class then a call to super will only work if the 
other person has written their class with a call to super... not 
good. Whereas if I call the class init explicitly it works regardless 
of how the superclass is written.

Thanks for a 'super' explanation Kent :-)

Alan G
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to