[CentralOH] __slots__
Mark Erbaugh
mark at microenh.com
Sat Oct 9 15:57:08 CEST 2010
On Oct 9, 2010, at 8:57 AM, Eric Floehr wrote:
> My understanding of slots is by doing that you would accomplish two main things:
>
> 1. Decrease instance storage space (because no __dict__), which could make a big difference if you are creating LOTS of instances.
> 2. Because there is no __dict__ you lose all the dynamic attribute capabilities of Python (which is certainly an acceptable tradeoff for improved memory management).
>
> So yes, it makes sense, as long as you understand what you are trading off and what you are gaining.
>
Eric,
Thanks.
In the particular case, there could be 100 or more instances and dynamic attributes are not needed.
FWIW, the class is a generic descriptor used to add dynamic properties do a larger class. If anyone is interested, I can post the code (it's around 200 lines).
Mark
More information about the CentralOH
mailing list