473,770 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

new style and classic style classes ?

Hello,
Please put some light on, What are new style classes and classic style
classes in python. The basic differences in them. And How can I decide
to choose one.

Dec 22 '05 #1
1 1443
ankit <an************ @gmail.com> wrote:
Hello,
Please put some light on, What are new style classes and classic style
classes in python. The basic differences in them. And How can I decide
to choose one.


"Classic" (old-style) classes are ones with no ancestor classes that are
built-in types; "new-style" classes are one with ancestor classes that
are built-ins (including the built-in type 'object', which exists for
the sole purpose of making classes new-style). New-style classes have a
clearer and better organized approach to attribute access, and allow you
to use such powerful features as 'property' to full effect.

Old-style classes exist only for backwards compatibility. The only good
reason to decide to make a class old-style is when you're making an
*exception* class, specifically: up to Python 2.4, exception classes
must be old-style.
Alex
Dec 22 '05 #2

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

Similar topics

3
3298
by: Sibylle Koczian | last post by:
I want to try out several applications, all doing the same thing but using different GUI libraries (Tkinter, Qt, wxWindows). Using an example I found in a book I wrote a class containing the GUI independent methods of the application, let's call it MyAppClass. The book is written before Python 2.2, so it uses classic classes, but I want some properties, so I made MyAppClass a new style class. For the Tkinter GUI I derive another class,...
12
3833
by: David MacQuigg | last post by:
I have what looks like a bug trying to generate new style classes with a factory function. class Animal(object): pass class Mammal(Animal): pass def newAnimal(bases=(Animal,), dict={}): class C(object): pass C.__bases__ = bases dict = 0
5
1526
by: Chris S. | last post by:
I'm generating the source of an object from a list of objects. Therefore I need to determine if the object is a class definition (i.e. 'def something(whatever):') or a class instance (i.e. 'somename = somethingelse()'). With classic classes this is trivial, since all I have to do is check the type. However, for the new "improved" style classes this seems next to impossible, since everything is essentially an instance of something. ...
0
1195
by: Skip Montanaro | last post by:
If I have a new-style class what are the restrictions that keep me from going back to a classic class? I know use of __slots__, __new__ or the property() builtin make new-style a requirement. What other constructs might the code be using that would prevent me from falling back to use of classic classes? Thx, Skip
38
2055
by: looping | last post by:
For Python developers around. >From Python 2.5 doc: The list of base classes in a class definition can now be empty. As an example, this is now legal: class C(): pass nice but why this syntax return old-style class, same as "class C:", and not the new style "class C(object):" ?
18
2757
by: Joel Hedlund | last post by:
Hi! The question of type checking/enforcing has bothered me for a while, and since this newsgroup has a wealth of competence subscribed to it, I figured this would be a great way of learning from the experts. I feel there's a tradeoff between clear, easily readdable and extensible code on one side, and safe code providing early errors and useful tracebacks on the other. I want both! How do you guys do it? What's the pythonic way? Are...
4
1260
by: Isaac Rodriguez | last post by:
Hi, This is probably a very basic question, but I've been playing with new style classes, and I cannot see any difference in behavior when a declare a class as: class NewStyleClass(object): or
26
1837
by: momobear | last post by:
hi, I am puzzled about how to determine whether an object is initilized in one class, anyone could give me any instructions? here is an example code: class coffee: def boil(self): self.temp = 80 a = coffer() if a.temp 60:
4
1111
by: Quek | last post by:
Hi all, I'm really new to Python and I've been reading up some texts on older versions of Python (2.2 to be specific). The text briefly mentioned new style and classic classes. I'd really like to know in the current context of Python 2.5, besides in the cases of multi-inheritance, where would I use new style classes? Is it a norm to use more new style classes even if I don't
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10002
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9869
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.