__slot__: what is it good for?

Stephen Hansen me+list/python at ixokai.io
Mon Jun 21 14:55:16 EDT 2010


On 6/21/10 11:06 AM, Terry Reedy wrote:
> On 6/21/2010 11:24 AM, Stephen Hansen wrote:
>> On 6/21/10 8:08 AM, Stephen Hansen wrote:
>>> If you don't want a class to have attributes added at runtime, the
> 
>> The Pythonic way to achieve that is to... simply NOT add attributes at
>> runtime.
>>
>> I.e., choose to follow the rule you've decided on.
> 
> Or add a __setattr__ method, but the above is easier.

I'd sort of argue that adding a __setattr__ for that purpose is
un-Pythonic (as opposed to using __setattr__ for some functional purpose
and that restriction being a side-effect). Its possible to do it, sure;
but its also possible to use __slots__ to do so as well. But its bad
form in both cases.

But, that argument is largely Nit meeting Pick and having a fight about
which kettle is blacker. :)

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20100621/8f13134b/attachment.sig>


More information about the Python-list mailing list