Daily Shaarli

All links of one day in a single page.

December 8, 2022

UsingSlots - Python Wiki

x1.slot1 = 1

---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

Input In [3], in <module>
----> 1 x1.slot1 = 1

AttributeError: 'Example' object has no attribute 'slot1'
python - Usage of __slots__? - Stack Overflow
thumbnail

Avoid them if you want to subclass variable length builtins like long, tuple, or str, and you want to add attributes to them.
Avoid them if you insist on providing default values via class attributes for instance variables.