attribute access and comparisons of two different objects
michele.simionato at poste.it
Wed Jun 16 06:08:22 CEST 2004
"Larry Bates" <lbates at swamisoft.com> wrote in message news:<V4KdnTIF-4yRZFPdRVn-ug at comcast.com>...
> 1) In Python 2.3 there is a new __slots__ methodology that
> does what you want with class attributes. One must wonder
> how everyone got by without it for so many years. I'm not
> sure I understand the "overhead" issue. Some code must be
> executed to determine if an attribute exists or not, why
> shouldn't it be up to the programmer to write it by
> overriding __setattr__ method?
__slots__ should never be used to restrict attribute access;
they are just a memory saving optimization; you are better off
not using it if you can. See this recipe:
Yes, overriding __setattr__ has a performance overhaud, so
just do not freeze your attributes! That's the Pythonic solution.
More information about the Python-list