Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30093 > unrolled thread

new-style class or old-style class?

Started byJayden <jayden.shui@gmail.com>
First post2012-09-25 07:44 -0700
Last post2012-09-26 17:30 -0700
Articles 10 — 10 participants

Back to article view | Back to comp.lang.python


Contents

  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

#30093 — new-style class or old-style class?

FromJayden <jayden.shui@gmail.com>
Date2012-09-25 07:44 -0700
Subjectnew-style class or old-style class?
Message-ID<2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com>
In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!!

[toc] | [next] | [standalone]


#30095

From"Littlefield, Tyler" <tyler@tysdomain.com>
Date2012-09-25 09:02 -0600
Message-ID<mailman.1342.1348585331.27098.python-list@python.org>
In reply to#30093
On 9/25/2012 8:44 AM, Jayden wrote:
> In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!!


Perhaps this is useful:
http://docs.python.org/reference/datamodel.html
It's 3.3 I think.

-- 
Take care,
Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave.

[toc] | [prev] | [next] | [standalone]


#30097

FromChris Angelico <rosuav@gmail.com>
Date2012-09-26 01:05 +1000
Message-ID<mailman.1344.1348585527.27098.python-list@python.org>
In reply to#30093
On Wed, Sep 26, 2012 at 12:44 AM, Jayden <jayden.shui@gmail.com> wrote:
> In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!!

Definitely go with new-style. In Python 3, old-style classes aren't
supported, and the syntax that would create an old-style class in
Python 2 will implicitly create a new-style class. (Explicitly
subclassing object still works in Py3, so you can happily use that
syntax for both.)

ChrisA

[toc] | [prev] | [next] | [standalone]


#30108

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-09-25 16:20 +0000
Message-ID<5061d9db$0$29981$c3e8da3$5496439d@news.astraweb.com>
In reply to#30093
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

[toc] | [prev] | [next] | [standalone]


#30118

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2012-09-25 19:45 +0100
Message-ID<mailman.1366.1348598713.27098.python-list@python.org>
In reply to#30108
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.

[toc] | [prev] | [next] | [standalone]


#30111

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2012-09-25 12:33 -0400
Message-ID<mailman.1358.1348590903.27098.python-list@python.org>
In reply to#30093
On Tue, 25 Sep 2012 07:44:04 -0700 (PDT), Jayden <jayden.shui@gmail.com>
declaimed the following in gmane.comp.python.general:

> In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!!

	In Python 3.x, you only have "new-style".

	In Python 2.x, it is preferable to use "new-style" as there are more
capabilities with them, but there is still code inherited from prior
versions using "old-style"
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#30191

FromRamchandra Apte <maniandram01@gmail.com>
Date2012-09-26 05:59 -0700
Message-ID<31ea72b0-353e-4eb4-85e1-cae52ec85260@googlegroups.com>
In reply to#30093
On Tuesday, 25 September 2012 20:14:05 UTC+5:30, Jayden  wrote:
> In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!!

Next time just Google your questions.
:-)
Good luck with Python

[toc] | [prev] | [next] | [standalone]


#30195

FromRoy Smith <roy@panix.com>
Date2012-09-26 09:12 -0400
Message-ID<roy-7EBE6F.09123326092012@news.panix.com>
In reply to#30093
In article <2e8a9e88-9e7e-43f7-a070-ea9054e625f2@googlegroups.com>,
 Jayden <jayden.shui@gmail.com> wrote:

> In learning Python, I found there are two types of classes? Which one are 
> widely used in new Python code? Is the new-style much better than old-style? 
> Thanks!!

If you're just learning Python 2.x, you might as well use new-style 
classes, since that's what all classes are in 3.x.

On the other hand, if you're just learning, it probably doesn't matter 
which kind you use.  Until you get into some pretty sophisticated stuff, 
you won't notice any difference between the two.

On the third hand, all it takes to create a new-style class is to have 
it inherit from object.  It's no big deal to write

>>> class Foo(object):

instead of just

>>> class Foo:

so you might as well use new-style classes :-)

[toc] | [prev] | [next] | [standalone]


#30233

Fromwxjmfauth@gmail.com
Date2012-09-26 13:15 -0700
Message-ID<f61f6eae-7993-4179-b091-d0d669ce9cc3@googlegroups.com>
In reply to#30093
Le mardi 25 septembre 2012 16:44:05 UTC+2, Jayden a écrit :
> In learning Python, I found there are two types of classes? Which one are widely used in new Python code? Is the new-style much better than old-style? Thanks!!

Use Python 3 and classes. 


-------

The interesting point or my question.

Why a Python beginner arrives here and should ask about this?

jmf

[toc] | [prev] | [next] | [standalone]


#30253

Fromalex23 <wuwei23@gmail.com>
Date2012-09-26 17:30 -0700
Message-ID<d3c147d2-9455-42a3-926b-919e04a06ab2@t2g2000pbt.googlegroups.com>
In reply to#30233
On Sep 27, 6:15 am, wxjmfa...@gmail.com wrote:
> The interesting point or my question.
> Why a Python beginner arrives here and should ask about this?

Would you prefer that they'd instead make some kind of false
assumption and then post endless screeds condemning it?

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web