私のクラスの多くは、アカウントを表す次のクラスのように見えます
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
しかし、実際に関連する情報は、私が気にかけている属性のリストだけですfirst, last, age, id, balance
。この構造に従う Python クラスを定義する標準的な方法はありますか?
一見、私は考えnamedtuple
ましたが、事後に追加のメソッドを追加できるかどうかはわかりません。本当に、私は次のようなものが欲しい
class Account(object):
attributes = "first last age id balance"
def ... # other methods
これを取得する最良の方法は何ですか?