I\'m storing a lot of complex data in tuples/lists, but would prefer to use small wrapper classes to make the data structures easier to understand, e.g.
class Pe
Using __slots__
decreases the memory footprint quite a bit (from 1.7 GB to 625 MB in my test), since each instance no longer needs to hold a dict
to store the attributes.
class Person:
__slots__ = ['first', 'last']
def __init__(self, first, last):
self.first = first
self.last = last
The drawback is that you can no longer add attributes to an instance after it is created; the class only provides memory for the attributes listed in the __slots__
attribute.