By default, instances of both old and new-style classes have a dictionary for attribute storage. This wastes space for objects having very few instance variables. The space consumption can become acute when creating large numbers of instances.
很多老的和新式的类的实例有一个字典,里面存储了很多属性。对于有限的变量的实例,这就浪费了很多空间。这些空间消耗随着创建实例的增多可以一直积累。
The default can be overridden by defining __slots__ in a new-style class definition. The __slots__ declaration takes a sequence of instance variables and reserves just enough space in each instance to hold a value for each variable. Space is saved because __dict__ is not created for each instance.
这些默认的可以被新的类中__slots__重载,__slot__申明会为每个实例分配足够的空间给一些实例变量,空间被保存,因为__dict__不是为每一个实例创建。