0

While there are several articles written about new classes versus old classed I wasn't able to see a basic example with old/new style.

1

2 Answers 2

2

The only syntactic difference is that new style classes inherit from object:

class Old:
    ...

class New(object):
    ....
Sign up to request clarification or add additional context in comments.

Comments

0

I believe this wiki post is what you are looking for:

 <snip> 
 The minor syntactic difference is that New Style Classes happen
 to inherit from object.

 class Old1:
     ...

 class Old2(Old1, UserDict): # Assuming UserDict is still old-style
     ...

 vs

 class New1(object):
     ... class New2(New1):
     ... class New3(Old1, New2):
     ... class New4(dict, Old1):  # dict is a newstyle class
 <snip>

2 Comments

class New4 is particularly nasty in your example: it is a new style class, but instead of having object as the last class in the MRO, the MRO actually goes New4, dict, object, Old1.
@Duncan I can't take credit for that example. It's directly copied from the linked Wiki page. I'll update my post to be clear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.