<div dir="ltr">The point here is 'which' foo is being called.  Since it seems to go from right to left, it finds mixin2's foo method first, and then when it finds mixin1's foo method second that becomes the one that is used...<div><br></div><div>At least that's what seems to be happening. </div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 4, 2017 at 9:20 PM, Minesh Patel <span dir="ltr"><<a href="mailto:minesh@gmail.com" target="_blank">minesh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">If the order was mixin2->mixin1->class A then wouldn't it have printed "<span style="font-size:12.8px">In mixin2.foo()"?</span><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px"><br></span></div></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Wed, Jan 4, 2017 at 10:07 AM, Braun Brelin <span dir="ltr"><<a href="mailto:bbrelin@gmail.com" target="_blank">bbrelin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">What I'm confused about is the following:<div><br></div><div><div> #!/usr/bin/env python3</div><div>  class mixin1(object):</div><div>      def foo(self):</div><div>          print ("In mixin1.foo()")</div><div>          </div><div>  class mixin2 (object):</div><div>     def foo(self):</div><div>          print ("In mixin2.foo()")</div><div>          </div><div>  class A(object):</div><div>      def __init__(self):</div><div>          print ("In class A")</div><div>          </div><div>  class B(A,mixin1,mixin2):</div><div>      def __init__(self):</div><div>          self.foo()</div><div>              </div><div> </div><div> myB = B()</div></div><div><br></div><div>------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>--------------------</div><div>The output of this program is: </div><div>In mixin1.foo()<br></div><div><br></div><div>So, it seems to be doing method resolution from right to left.  No?</div><div><br></div><div>Braun</div><div><br></div><div><br></div><div><br></div><div>I've always understood that the class hierarchy when determining inheritance is that Python looks at class mixin2 first, then class mixin1, then the base class A.  I.e. the order is right to left.  A number of web site</div></div><div class="m_-8337981007675260267HOEnZb"><div class="m_-8337981007675260267h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 4, 2017 at 7:37 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>C's MRO is (C, A, B, object), and method lookup happens in that order. So if both A and B define a method m, but C doesn't, A.m gets used.<br><br></div>For old-style classes the lookup order would still be (C, A, B).<br><br>Maybe you can clarify *what* is happening from right to left in your understanding? Code speaks!<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-8337981007675260267m_-5157079647499484929h5">On Wed, Jan 4, 2017 at 9:30 AM, Braun Brelin <span dir="ltr"><<a href="mailto:bbrelin@gmail.com" target="_blank">bbrelin@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-8337981007675260267m_-5157079647499484929h5"><div dir="ltr">Hi all, <div><br></div><div>I'm trying to figure out how to understand Python's Method Resolution order.</div><div>One of the things that's really confusing me is that from my understanding</div><div>if I have a class declaration like this</div><div><br></div><div>class C(A,B):</div><div>      ...</div><div><br></div><div>Python does the inheritance order from right to left, yet all the tutorials on MRO</div><div>start talking about inheritance from left to right. </div><div><br></div><div>Is the right to left order a property of the older Python 2 style classes that didn't </div><div>explicitly inherit from object?</div><div><br></div><div>Thanks</div><div><br></div><div><br></div></div>
<br></div></div>______________________________<wbr>_________________<br>
Baypiggies mailing list<br>
<a href="mailto:Baypiggies@python.org" target="_blank">Baypiggies@python.org</a><br>
To change your subscription options or unsubscribe:<br>
<a href="https://mail.python.org/mailman/listinfo/baypiggies" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/baypiggies</a><span class="m_-8337981007675260267m_-5157079647499484929HOEnZb"><font color="#888888"><br></font></span></blockquote></div><span class="m_-8337981007675260267m_-5157079647499484929HOEnZb"><font color="#888888"><br><br clear="all"><br>-- <br><div class="m_-8337981007675260267m_-5157079647499484929m_1311211254374542653gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</font></span></div>
</blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<br>
Baypiggies mailing list<br>
<a href="mailto:Baypiggies@python.org" target="_blank">Baypiggies@python.org</a><br>
To change your subscription options or unsubscribe:<br>
<a href="https://mail.python.org/mailman/listinfo/baypiggies" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/baypiggies</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br></div></div><div class="m_-8337981007675260267gmail_signature" data-smartmail="gmail_signature">Thanks,<br>--Minesh</div>
</div>
</blockquote></div><br></div>