14 Feb
2013
14 Feb
'13
3:32 p.m.
On Feb 14, 2013 6:20 AM, "Nick Coghlan"
A recurring suggestion for collections.namedtuple is that it would be nice to be able to define them like this (as it not only avoids having to repeat the class name, but also allows them to play nicely with pickle and other name-based reference mechanisms):
class MyTuple(collections.NamedTuple): __fields__ = "a b c d e".split()
Something similar that I've been using: @as_namedtuple("a b c d e") class MyTuple: """My namedtuple with extra stuff.""" @property def something_special(self): """...""" return ... Support for default values is also something I've added, but that's relatively orthogonal to this discussion. -eric