Re: Calling __init__ with multiple inheritance

2005-03-29 Thread Axel Straschil
Hello! >> Also, lool at that: >> class Mother(object): >> def __init__(self, param_mother='optional', **eat): >> print 'Mother' >> class Father(object): >> def __init__(self, param_father='optional', **eat): >> print 'Father' >> class Child(Mother, Father): >> def __init__(self, **ham): >> super(C

Re: Calling __init__ with multiple inheritance

2005-03-29 Thread jfj
Peter Otten wrote: Child() child father mother parent # <-- parent only once <__main__.Child object at 0x402ad38c> D-uh? class Parent(object): def __init__(self): print "parent" super(Parent, self).__init__() class Father

Re: Calling __init__ with multiple inheritance

2005-03-29 Thread Peter Otten
Axel Straschil wrote: > Thanks to all for the very interesting postings! You're welcome. > I came to the following: > > For single inheritance, super is a nice tool if you will recfactoring > the class later. Or if you start out with a diamond inheritance graph from the beginning. > For mul

Re: Calling __init__ with multiple inheritance

2005-03-28 Thread Steven Bethard
Axel Straschil wrote: I came to the following: For single inheritance, super is a nice tool if you will recfactoring the class later. For multiple inheritance, if you want to use super, you have to have very much knowledge of the classes you inheritance. And for multiple inheritance, if you don't

Re: Calling __init__ with multiple inheritance

2005-03-28 Thread Axel Straschil
Hello! Thanks to all for the very interesting postings! I came to the following: For single inheritance, super is a nice tool if you will recfactoring the class later. For multiple inheritance, if you want to use super, you have to have very much knowledge of the classes you inheritance. For m

Re: Calling __init__ with multiple inheritance

2005-03-28 Thread Peter Otten
jfj wrote: > As for the case where the users of the library want to subclass, I don't > see a problem.  They know they must subclass from class XXX and so they > call XXX.__init__ to construct it. I was thinking of class Child(Father, Mother): pass where Father and Mother have a common bas

Re: Calling __init__ with multiple inheritance

2005-03-28 Thread Robert Dick
jfj: > In the case of Parent diamond inheritance, super() can avoid calling > the __init__ of parent twice? How? Guido has a nice description of it: http://www.python.org/2.2.3/descrintro.html#cooperation. It linearizes the graph. Unfortunately, this means that super delegates to siblings. T

Re: Calling __init__ with multiple inheritance

2005-03-28 Thread jfj
Peter Otten wrote: jfj wrote: Peter Otten wrote: Here is an alternative approach that massages the initializer signatures a bit to work with super() in a multiple-inheritance environment: super(Father, self).__init__(p_father=p_father, **more) Is there any advantage using super in this cas

Re: Calling __init__ with multiple inheritance

2005-03-28 Thread Michael Spencer
[EMAIL PROTECTED] wrote: What if I want to call other methods as well? Modifying your example a bit, I'd like the reset() method call of Child to invoke both the Mother and Father reset() methods, without referencing them by name, i.e., Mother.reset(self). --- class Mother(object):

Re: Calling __init__ with multiple inheritance

2005-03-28 Thread Peter Otten
jfj wrote: > Peter Otten wrote: >> Here is an alternative approach that massages the initializer signatures >> a bit to work with super() in a multiple-inheritance environment: > >> super(Father, self).__init__(p_father=p_father, **more) > > > Is there any advantage using super in this

Re: Calling __init__ with multiple inheritance

2005-03-28 Thread jfj
Peter Otten wrote: Here is an alternative approach that massages the initializer signatures a bit to work with super() in a multiple-inheritance environment: super(Father, self).__init__(p_father=p_father, **more) Is there any advantage using super in this case? I think the case Father._

Re: Cooperative methods, was Re: Calling __init__ with multiple inheritance

2005-03-28 Thread phil_nospam_schmidt
Peter Otten wrote: > The problem with that aren't incompatible signatures, but the lack of an > implementation of the reset() method at the top of the diamond-shaped > inheritance graph that does _not_ call the superclass method. That method > could be basically a noop: Ok, now that's cool! Up

Cooperative methods, was Re: Calling __init__ with multiple inheritance

2005-03-28 Thread Peter Otten
[EMAIL PROTECTED] wrote: > What if I want to call other methods as well? Modifying your example a > bit, I'd like the reset() method call of Child to invoke both the > Mother and Father reset() methods, without referencing them by name, > i.e., Mother.reset(self). [example snipped] The problem w

Re: Calling __init__ with multiple inheritance

2005-03-28 Thread phil_nospam_schmidt
What if I want to call other methods as well? Modifying your example a bit, I'd like the reset() method call of Child to invoke both the Mother and Father reset() methods, without referencing them by name, i.e., Mother.reset(self). --- class Mother(object): def __init__(self, p

Re: Calling __init__ with multiple inheritance

2005-03-28 Thread Peter Otten
Axel Straschil wrote: > Im working with new (object) classes and normaly call init of ther > motherclass with callin super(...), workes fine. > > No, I've got a case with multiple inherance and want to ask if this is > the right and common case to call init: > > class Mother(object): > def __ini