What are new-style classes?

Terry Hancock hancock at anansispaceworks.com
Sun Aug 28 21:11:34 CEST 2005


On Sunday 28 August 2005 04:47 am, Vaibhav wrote:
> I recently heard about 'new-style classes'. I am very sorry if this
> sounds like a newbie question, but what are they? I checked the Python
> Manual but did not find anything conclusive. Could someone please
> enlighten me? Thanks!

"New style" classes are becoming the standard in Python, and must
always be declared as a subclass of a new style class, including built-in
classes. The simplest is "object", so the simplest newstyle class is:

class no_class(object):
	pass

as opposed to the simplest "old style" object which didn't inherit at all:

class really_no_class:
	pass

I would regard the latter as deprecated now, since it basically doesn't
buy you anything to use it. The only reason to hang on to old style
classes would seem to be to avoid breaking older code that relied on
details such as the order of multiple inheritence, which have changed.

So if you're just learning, just use new style classes exclusively, and
use the documentation that applies to them.  I think it's fairly non-
controversial that new style classes are an improved design.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com




More information about the Python-list mailing list