Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion new-style class or old-style class?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Steven D'Aprano  
View profile  
 More options Sep 25 2012, 12:20 pm
Newsgroups: comp.lang.python
From: Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info>
Date: 25 Sep 2012 16:20:44 GMT
Local: Tues, Sep 25 2012 12:20 pm
Subject: Re: new-style class or old-style class?

On Tue, 25 Sep 2012 07:44:04 -0700, Jayden wrote:
> In learning Python, I found there are two types of classes? Which one
> are widely used in new Python code?

New-style classes.

> Is the new-style much better than old-style?

Yes.

Always use new-style classes, unless you have some specific reason for
needing old-style ("classic") classes.

Advantages of new-style classes:

1) They are the future. In Python 3, all classes are "new-style" and
classic classes are gone.

2) Multiple inheritance works correctly. Multiple inheritance for classic
classes is buggy.

3) New-style classes support awesome features like super(), properties,
descriptors, and __getattribute__. Old-style do not.

The main disadvantage is that automatic delegation is a pain to do
correctly in new-style classes, but trivially simple in classic classes.
Still, all things considered, it's a good trade.

--
Steven


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.