Python Knowledge


Use slots

Defining the class variable __slots__ as a tuple of variable names will replace the usual __dict__ instance variable with a global, invariable one. This will restrict the creation of new instance variables, but it will greatly improve the memory use when several instances are created.

More information here