I am interested in building agent-based models of economic systems in Python. Typical model might have many thousands of agents (i.e., firms, consumers, etc).
Typical firm agent class might look something like:
class Firm(object):
def __init__(capital, labor, productivity):
self.capital = capital
self.labor = labor
self.productivity = productivity
In most of my models, attributes are not dynamically created and thus I could write the class using __slots__
:
class Firm(object):
__slots__ = ('capital', 'labor', 'productivity')
def __init__(capital, labor, productivity):
self.capital = capital
self.labor = labor
self.productivity = productivity
However, it seems that the use of __slots__
is generally discouraged. I am wondering if this be a legitimate/advisable use case for __slots__
.