Python object overhead?
Jean-Paul Calderone
exarkun at divmod.com
Mon Mar 26 11:33:12 EDT 2007
On Mon, 26 Mar 2007 09:13:58 -0600, Matt Garman <matthew.garman at gmail.com> wrote:
>On 3/23/07, Jack Diederich <jackdied at jackdied.com> wrote:
>> If you make the record a new style class (inherit from object) you can
>> specify the __slots__ attribute on the class. This eliminates the per
>> instance dictionary overhead in exchange for less flexibility.
>
>When you say "new style class", do you mean that the __slots__ feature
>is only available in a newer version of Python? Unfortunately, I'm
>stuck on 2.3.4 for this project.
A new-style class is one which has a type of type instead of ClassType.
For example:
>>> class notnewstyle:
... pass
...
>>> type(notnewstyle)
<type 'classobj'>
>>> class newstyle(object):
... pass
...
>>> type(newstyle)
<type 'type'>
>>> class alsonewstyle(list):
... pass
...
>>> type(alsonewstyle)
<type 'type'>
>>>
2.3 has new-style classes.
Jean-Paul
More information about the Python-list
mailing list