Copying objects style questions
Alex Martelli
aleax at aleax.it
Wed Aug 6 18:35:51 EDT 2003
Bob Halley wrote:
>> To forestall further misunderstandings -- this would not work for
>> objects with __slots__ (no __dict__) or inheriting from classes with
>> __slots__ (wouldn't copy attributes not in __dict__) -- there is
>> always more work needed for such cases. But if one uses __slots__
>> one *deserves* to have to work a bit harder as a result;-).
>
> I use new-style classes with __slots__ :), because it makes a really
> noticeable difference in memory usage if you use dnspython to work
> with a good-sized zone (i.e. one with tens of thousands of records).
If you have huge numbers of instances of a class, it sure may well make
sense to give the class __slots__ in order to save memory -- that's what it
was introduced for. But then, giving that class a __copy__, or the like,
which knows about its slots (or using the deep dark magic of _reduce_ex,
I guess...), if you need to perform fancier copies than ordinary copy.copy
or copy.deepcopy would do for you, seems fair enough to me:-).
Alex
More information about the Python-list
mailing list