How can namedtuples be extended or subclassed with many additional @properties ?
For a few, one can just write the text below; but there are many,
so I\'m looking for a gene
How about this?
class Top( namedtuple( "Top_", "topid amount personid" )):
""" @property
.person -> persontable[personid]
.pname -> person.pname ...
"""
__slots__ = ()
@property
def person(self):
return persontable[self.personid]
def __getattr__(self,attr):
if attr in Person._fields:
return getattr(self.person, attr)
raise AttributeError("no such attribute '%s'" % attr)