__slots__

Aahz aahz at pythoncraft.com
Fri Mar 24 18:10:12 CET 2006


In article <sFKUf.12114$wD1.3624 at trnddc02>,
David Isaac <aisaac0 at verizon.net> wrote:
>"Ziga Seilnacht" <ziga.seilnacht at gmail.com> wrote:
>>
>> If you want to restrict  attribute asignment, you should use the
>> __setattr__ special method, see:
>> http://docs.python.org/ref/attribute-access.html
>
>That "should" is what I am asking about. If I understand,
>in the simplest case, you want me to say something like
>        def __setattr__(self,name,value):
>            if name in myattrlist:
>                object.__setattr__(self,name,value)
>            else:
>                raise AttributeError
>instead just saying
>        __slots__ = myattrlist
>I understand that this *is* the prevailing advice.  But why?

Because __slots__ breaks with inheritance.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Look, it's your affair if you want to play with five people, but don't
go calling it doubles."  --John Cleese anticipates Usenet



More information about the Python-list mailing list