473,324 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

New-style classes questions

I'm confused by the concepts of old-style vs new-style classes, I've read
most of the documents I found about this but it doesn't "click". Probably
because I wasn't around before 2.2.

Anyway, the reason for new style classes are to make the whole type/object
thing work better together. There are a number of new features etc.

I think my problem is when new-style classes are used, at first I thought
that all classes become new-style classes when I was using 2.4, but if I
understand things correctly I need to subclass an existing class (assuming
that this class does the same) for it to become a new-style class.

Have I understood this correctly?

If I have, then I've got the following question:
================================================
Then I could write:

class Foo( Object )

to make a new-style class, and

class FooA

to make an old-style class.
What is the reason for allowing both styles? (backwards compatibility??)

When I make my own classes should they always be new-style objects or are
there reasons for using old-style object?
================================================
Sep 25 '05 #1
3 1259
> What is the reason for allowing both styles? (backwards compatibility??)

yes.

When I make my own classes should they always be new-style objects or are
there reasons for using old-style object?


No, use new style if you can - except from the rare cases where above
mentioned backwards compatibilty is needed. E.g. exceptions have to be
old-style, and for example omniorb needs old-style classes for corba
implementations.

Diez
Sep 25 '05 #2
Diez B. Roggisch wrote:
What is the reason for allowing both styles? (backwards compatibility??)


yes.


Note that there is another way to create new-style classes:

__metaclass__ = type

before the first class definition:
class Foo: pass .... type(Foo) <type 'classobj'> __metaclass__ = type
class Bar: pass .... type(Bar)

<type 'type'>

I like this. However, perhaps other people reading my source code won't
like it, because when they see 'class Foo:', they might expect an
old-style class. But it's so much better to type and to read, that I
prefer this.

Does the Python style guide have any severe penalty for using this?

regards,
Gerrit.

--
Temperature in Luleå, Norrbotten, Sweden:
| Current temperature 05-09-25 15:19:47 11.0 degrees Celsius ( 51.9F) |
--
Det finns inte dåligt väder, bara dåliga kläder.
Sep 25 '05 #3
On Sun, 25 Sep 2005 15:24:29 +0200, Gerrit Holl wrote
(in article <ma************************************@python.org >):
I like this. However, perhaps other people reading my source code won't
like it, because when they see 'class Foo:', they might expect an
old-style class. But it's so much better to type and to read, that I
prefer this.
I personally would find this more difficult to read but it's a matter of
taste I suppose.
Det finns inte dåligt väder, bara dåliga kläder.


Så sant som det var sagt
jem

Sep 25 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Madestro | last post by:
Hi guys, I am making a small program to retrieve e-mails from POP accounts. I got all the e-mail parsing stuff figured out, but I cannot seem to come up with a way to find out which e-mails are...
3
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. I am...
20
by: Razvan | last post by:
Hi ! Is there any difference between new X and new X() ?! Regards, Razvan
11
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have...
5
by: kUfa.scoopex | last post by:
Hi there! I have a small problem, and i really dont see any convenient way to fix it. Basically, i'd like to overload global new operators, into something like this: void *operator new(...
2
by: Dave | last post by:
Hello all, I'd like to find a source on the web that discusses, in a comprehensive manner and in one place, everything about new / delete. It should include overloading operator new, the new...
1
by: scorpiotgs | last post by:
I downloaded a script for a menu (below) but I want all the links i this part(ze_menu3) to open in a new window. this probably a noob question, but i couldnt figure it out, so pleas help me ...
15
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any...
7
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls...
3
by: Grizlyk | last post by:
Hi, people. Can anybody explain me "multiple 'new' at single line" behavior. Consider: p::p(void*); p::p(void*,void*); new A( p(new B), p( new C(p(new D), p(new E)) ), p(new F));
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.