__slots__

Brad Clements bkc at Murkworks.com
Tue Nov 11 10:34:52 EST 2003


_
"Alex Martelli" <aleax at aleax.it> wrote in message
news:Z4Prb.1721$hV.54346 at news2.tin.it...

> __slots__ is meant as a special-purpose memory optimization to
> save the per-instance memory cost of a dictionary when you're
> defining small classes of which a huge number of instances are
> meant to exist at the same time, so that the several tens of bytes
> per instance that a dictionary might cost is an unacceptable price
> to pay compared to the "actual" footprint of each of the huge
> number of instances.

And I'd like to add.. I was starting a new embedded Python project when
__slots__ came out, the documentation at the time didn't make clear their
intended use of storage optimization.  Rather what *I* read into it was a
way to reduce the possibility of error by mistyping an instance attribute.
Now, why I thought this was neat is beyond me, since in my vast 4 years of
Python programming I've never really had that problem anyway.

But nonetheless I slotted myself into a corner anyway. Now I have to undo
all those nasty slots statements.

My advice.. forget __slots__!









More information about the Python-list mailing list