Are all classes new-style classes in 2.4+?

Felipe Almeida Lessa felipe.lessa at gmail.com
Sun Dec 31 07:59:15 EST 2006


On 31 Dec 2006 03:57:04 -0800, Isaac Rodriguez
<isaac.rodriguez at comcast.net> wrote:
> I am using Python 2.4, and I was wondering if by default, all
> classes are assumed to be derived from "object".

This won't tell you advantages or disadvantages, but will show you
that the default still is the old-style:

>>> class old:
...     pass
...
>>> type(old())
<type 'instance'>
>>> dir(old())
['__doc__', '__module__']
>>>
>>> class new(object):
...     pass
...
>>> type(new())
<class '__main__.new'>
>>> dir(new())
['__class__', '__delattr__', '__dict__', '__doc__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__',
'__weakref__']


In general, even if you don't understand the differences, it's better
to use new-style (they're new ;-). Anyway, see
http://effbot.org/pyref/new-style-and-classic-classes.htm for a little
more information.

-- 
Felipe.



More information about the Python-list mailing list