[Python-Dev] Py2.6 ideas

Raymond Hettinger python at rcn.com
Fri Feb 16 02:12:30 CET 2007


[Raymond Hettinger]
>>> * Add a pure python named_tuple class to the collections module.
>>> I've been using the class for about a year and found that it greatly
>>> improves the usability of tuples as records.
>>> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/500261

[Delaney, Timothy]
> Hmm - possibilities. "record" definitely has greater connotations of
> heterogeneous elements than "tuple", which would put paid to the
> constant arguments that "a tuple is really just an immutable list".

No need to go so widely off-track.  The idea is to have an efficient type that 
is directly substitutable for tuples but is a bit more self-descriptive.  I like 
to have the doctest result cast at NamedTuple('TestResults failed attempted). 
The repr of that result looks like  TestResult(failed=0, attempted=15) but is 
still accessible as a tuple and passes easily into other functions that expect a 
tuple.  This sort of thing would be handly for things like os.stat(). 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/500261


Raymond 


More information about the Python-Dev mailing list