Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

Aahz aahz at pythoncraft.com
Fri Aug 25 10:34:50 EDT 2006


In article <1156508104.583914.323700 at b28g2000cwb.googlegroups.com>,
 <bearophileHUGS at lycos.com> wrote:
>Andre Meyer:
>>
>> Is the test meaningful and are you surprised by the results?
>> I am, actually, because I would have assumed that attribute access
>> with an object should be faster because lookup can be precompiled.
>
>The results seem okay. Python is a dynamic language, object attributes
>(and methods, etc) are kept inside a dict, where you can add and remove
>them when you like. So using a dict is faster.
>You can also take a look at __slots__

Taking a look at __slots__ is fine as long as you don't actually use
them.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it."  --Brian W. Kernighan



More information about the Python-list mailing list