Reduce memory usage in Python using slots
slots is a kind of Python magic that reduces memory usage of a program. It’s useful only when we have a lot objects with fixed number of attributes. For example let’s assume we have a online shopping website. whenever a user adds a item to the cart, we create a object for that item. For example,
1 2 3 4 5 class CartItem(object): def __init__(self, item_id, added_time): self._item_id = item_id self.