Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30118
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Subject | Re: new-style class or old-style class? |
| Date | 2012-09-25 19:45 +0100 |
| References | <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com> <5061d9db$0$29981$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1366.1348598713.27098.python-list@python.org> (permalink) |
On 25/09/2012 17:20, Steven D'Aprano wrote:
> 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.
>
>
>
Thanks for this reminder, my port of the J word code to Python has just
been simplified :)
--
Cheers.
Mark Lawrence.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
new-style class or old-style class? Jayden <jayden.shui@gmail.com> - 2012-09-25 07:44 -0700
Re: new-style class or old-style class? "Littlefield, Tyler" <tyler@tysdomain.com> - 2012-09-25 09:02 -0600
Re: new-style class or old-style class? Chris Angelico <rosuav@gmail.com> - 2012-09-26 01:05 +1000
Re: new-style class or old-style class? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-25 16:20 +0000
Re: new-style class or old-style class? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-25 19:45 +0100
Re: new-style class or old-style class? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-25 12:33 -0400
Re: new-style class or old-style class? Ramchandra Apte <maniandram01@gmail.com> - 2012-09-26 05:59 -0700
Re: new-style class or old-style class? Roy Smith <roy@panix.com> - 2012-09-26 09:12 -0400
Re: new-style class or old-style class? wxjmfauth@gmail.com - 2012-09-26 13:15 -0700
Re: new-style class or old-style class? alex23 <wuwei23@gmail.com> - 2012-09-26 17:30 -0700
csiph-web