understanding the concept of method resolution ordering in python -


when call x=d() why c's init() not getting called b's init() getting called , d's constructor..should'nt order b,a,c,d secondly,x.f() shows error wrong argument passing ..

enter image description here

what doing wrong??

concerning f, forgot self keyword declare them methods.

for calls constructors, need use 'super' in each , every class of inheritance tree.

class a(object):     def __init__(self):         super(a, self).__init__()         print "a.__init__"      def f(self):         print "a.f"  class b(a, object):     def __init__(self):         super(b, self).__init__()         print "b.__init__"  class c(object):     def __init__(self):         super(c, self).__init__()         print "c.__init__"      def f(self):         print "c.f"  class d(b, c, object):     def __init__(self):         super(d, self).__init__()         print "d.__init__"  x = d() x.f() 

and :

c.__init__ a.__init__ b.__init__ d.__init__ a.f 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -