Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > new-style class or old-style class?

Reply
Thread Tools

new-style class or old-style class?

 
 
Jayden
Guest
Posts: n/a
 
      09-25-2012
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!!
 
Reply With Quote
 
 
 
 
Littlefield, Tyler
Guest
Posts: n/a
 
      09-25-2012
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.

 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      09-25-2012
On Wed, Sep 26, 2012 at 12:44 AM, Jayden <(E-Mail Removed)> 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
 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      09-25-2012
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
 
Reply With Quote
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      09-25-2012
On Tue, 25 Sep 2012 07:44:04 -0700 (PDT), Jayden <(E-Mail Removed)>
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
http://www.velocityreviews.com/forums/(E-Mail Removed) HTTP://wlfraed.home.netcom.com/

 
Reply With Quote
 
Mark Lawrence
Guest
Posts: n/a
 
      09-25-2012
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.

 
Reply With Quote
 
Ramchandra Apte
Guest
Posts: n/a
 
      09-26-2012
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
 
Reply With Quote
 
Roy Smith
Guest
Posts: n/a
 
      09-26-2012
In article <(E-Mail Removed)>,
Jayden <(E-Mail Removed)> 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
 
Reply With Quote
 
wxjmfauth@gmail.com
Guest
Posts: n/a
 
      09-26-2012
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 arewidely 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
 
Reply With Quote
 
alex23
Guest
Posts: n/a
 
      09-27-2012
On Sep 27, 6:15*am, (E-Mail Removed) 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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
Generic class literals - e.g,, Class<Map<String, Integer>>.class Purush Java 4 04-13-2005 08:40 PM
instanciate a class in a jar file with class.forname, while my main class is in another jar cyril Java 2 08-25-2004 06:55 AM



Advertisments