Scott David Daniels wrote:

>> I do understand the lookup for foo: foo is provided by both classes A 
>> and B and I do not state which one I want to use, so it takes the 
>> first one in the list of inherited classes (order of the declaration). 
>> However
>> I cannot find an explanation (I may have googled the wrong keywords) 
>> for the order of the __init__ calls from C. I was expecting (following 
>> the same order as the method lookup):
> 
> 
> This should make it clear:
>     class A (object):
>         def __init__ (self):
>             print '<A>',
>             super (A, self) .__init__ ()
>             print '</A>'
>     class B (object):
>         def __init__ (self):
>             print '<B>',
>             super (B, self) .__init__ ()
>             print '</B>'
>     class C (A, B):
>         def __init__ (self):
>             print '<C>',
>             super (C, self) .__init__ ()
>             print '</C>'
> 
>     C()
> 

Gosh, based on your code I added an attribute foo on both A and B, and I 
now understand... The super goes through all the super classes init to 
find the attributes that may have name conflict and keep the value of 
the attribute baesd upon the order of the class declaration in the 
definition of C (here the value of foo in A). Am I right? I am mostly 
using old style (without type unification) init but this motivate the 
shift for the new style. Is there somewhere a document about this?

Thanks a lot Scott

-- 
rafi

        "Imagination is more important than knowledge."
                                    (Albert Einstein)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to