title: Method resolution order in python
body: <p>I am new to python. I am using python 2.7. I was going through method order resolution with a small snippet as follows:</p>
  
  <pre><code>class A(object):
      attr = 'A'
  
  class B(A):
      pass
  
  class C(A):
      attr = 'C'
  
  class D(B,C):
      pass
  
  x = D()
  print x.attr
  </code></pre>
  
  <p>The order of resolution is x,D,B,C,A and hence the output would be C. Going by the above example, i made a small change to the code.</p>
  
  <pre><code>class A(object):
      attr = 'A'
  
  class E(object):
      attr = 'E'
  
  class B(A):
      pass
  
  class C(E):
      attr = 'C'
  
  class D(B,C):
      pass
  
  x = D()
  print x.attr
  </code></pre>
  
  <p>Going by my previous example, i expected the order to be x,D,B,C,A,E. To my surprise the output was "A". Hence i got confused with the order of resolution in new-style class. Can someone clarify on when B's parent was accessed before C class. Thanks.</p>