Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 496491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:41:28+00:00 2026-05-13T05:41:28+00:00

In the book Python in a Nutshell (2nd Edition) there is an example which

  • 0

In the book Python in a Nutshell (2nd Edition) there is an example which uses
old style classes to demonstrate how methods are resolved in classic resolution order and
how is it different with the new order.

I tried the same example by rewriting the example in new style but the result is no different than what was obtained with old style classes. The python version I am using to run the example is 2.5.2. Below is the example:

class Base1(object):  
    def amethod(self): print "Base1"  

class Base2(Base1):  
    pass

class Base3(object):  
    def amethod(self): print "Base3"

class Derived(Base2,Base3):  
    pass

instance = Derived()  
instance.amethod()  
print Derived.__mro__  

The call instance.amethod() prints Base1, but as per my understanding of the MRO with new style of classes the output should have been Base3. The call Derived.__mro__ prints:

(<class '__main__.Derived'>, <class '__main__.Base2'>, <class '__main__.Base1'>, <class '__main__.Base3'>, <type 'object'>)

I am not sure if my understanding of MRO with new style classes is incorrect or that I am doing a silly mistake which I am not able to detect. Please help me in better understanding of MRO.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:41:29+00:00Added an answer on May 13, 2026 at 5:41 am

    The crucial difference between resolution order for legacy vs new-style classes comes when the same ancestor class occurs more than once in the “naive”, depth-first approach — e.g., consider a “diamond inheritance” case:

    >>> class A: x = 'a'
    ... 
    >>> class B(A): pass
    ... 
    >>> class C(A): x = 'c'
    ... 
    >>> class D(B, C): pass
    ... 
    >>> D.x
    'a'
    

    here, legacy-style, the resolution order is D – B – A – C – A : so when looking up D.x, A is the first base in resolution order to solve it, thereby hiding the definition in C. While:

    >>> class A(object): x = 'a'
    ... 
    >>> class B(A): pass
    ... 
    >>> class C(A): x = 'c'
    ... 
    >>> class D(B, C): pass
    ... 
    >>> D.x
    'c'
    >>> 
    

    here, new-style, the order is:

    >>> D.__mro__
    (<class '__main__.D'>, <class '__main__.B'>, <class '__main__.C'>, 
        <class '__main__.A'>, <type 'object'>)
    

    with A forced to come in resolution order only once and after all of its subclasses, so that overrides (i.e., C’s override of member x) actually work sensibly.

    It’s one of the reasons that old-style classes should be avoided: multiple inheritance with “diamond-like” patterns just doesn’t work sensibly with them, while it does with new-style.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 292k
  • Answers 292k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There's this already asked... How to make email field unique… May 13, 2026 at 6:18 pm
  • Editorial Team
    Editorial Team added an answer query() method returns an array contains last inset id and… May 13, 2026 at 6:18 pm
  • Editorial Team
    Editorial Team added an answer It's an interesting problem, but let's discuss the compiler error… May 13, 2026 at 6:18 pm

Related Questions

I am reading the book Think Python by Allen Downey. For chapter 4, one
I'm reading How to think like a computer scientist which is an introductory text
A little background: I'm in the process of learning Python through O'Reilly's, Learning Python
I'm learning how to use sqlite3 with python. The example in the text book
I remember reading in Douglas Crockford's Javascript the Good Parts book that there is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.