I have the following piece of code :-
class A(object):
def __init__(self):
print "I'm in A"
def awesome_function(self):
raise NotImplementedError
class B(A):
def awesome_function(self):
print "Implemented in B"
class C(object):
def awesome_function(self):
print "Implemented in C"
class D(A,C):
def another_function(self):
print "hello world"
class E(C,A):
def another_function(self):
print "hello world"
try:
a = A()
a.awesome_function()
except Exception as e:
print "NotImplementedError"
pass
try:
b = B()
b.awesome_function()
except Exception as e:
print "NotImplementedError in b"
try:
d = D()
d.awesome_function()
except Exception as e:
print "NotImplementedError in d"
try:
e = E()
e.awesome_function()
except Exception as s:
print "NotImplementedError in e"
And the output I get is :-
I'm in A
NotImplementedError
I'm in A
Implemented in B
I'm in A
NotImplementedError in d
I'm in A
Implemented in C
Why does E work and D not work?
I would assume that functions get populated in a class's dict from left to right, in the order I mention in the inheritence. However, it seems like it's going from right to left?