Many of my classes look like the following class to represent accounts
class Account(object):
def __init__(self, first, last, age, id, balance):
self.first = first
self.last = last
self.age = age
self.id = id
self.balance = balance
def _info(self):
return self.first, self.last, self.age, self.id, self.balance
def __eq__(self, other):
return self._info == other._info()
def __hash__(self):
return hash((type(self), self.info()))
def ... # other methods follow
But really the only relevant information is the list of attributes I care about first, last, age, id, balance
. Is there a standard method to define Python classes that follow this structure?
At first glance I thought of namedtuple
but I'm not sure that that allows me to add additional methods after the fact. Really, I want something like the following
class Account(object):
attributes = "first last age id balance"
def ... # other methods
What is the best way of obtaining this?