How to use __slots__ in your own class
24 Sep 2016 | programming technique pythonBy default, Python stores instance attributes in a per-instance dictionay named __dict__. Dictionaries, nonetheless, have a significant memory overhead because of the underlying hash table used to provide fast access. If you are dealing with millions of instances with few attributes, the __slots__ class attribute can save a lot of memory, by letting the interpreter store the instance attributes in a tuple instead of a dict. Let’s check out how to achieve this.