This script allows you a fast, lightweight attribute-style access to tuples. It contains a function that returns a new subclass of tuple with named fields.
to tuples. It contains a function that returns a new subclass of tuple with named fields.
The principal features are:
- Easy to type/read/modify function signature: NamedTuple(’Person’, ‘name age sex height nationality’)
- C-speed attribute lookup using property and itemgetter.
- No instance dictionary means that instances take no more space than a regular tuple.
- Nice docstring is helpful with an editor’s tooltips.
- Optional keywords in the contructor for readability and to allow variable order of specifying arguments: Person(name=’susan’, height=60, nationality=’english’, sex=’f', age=30).
- Key/Value style repr for clearer error messages and for usability at the interactive prompt.
- Named tuples are picklable.
- Clean error messages for missing or misnamed arguments.
- A method similar to str.replace() using a field name (used instead of slicing for updating fields — instead of t[:2]+newval+t[3:], write t.replace(’f',newval)).
Download from: Homepage
Author:
Time:
Friday, June 20th, 2008 at 10:15 am
Category:
Comments:
You can leave a response, or trackback from your own site.
RSS:
You can follow any responses to this entry through the RSS 2.0 feed.
Navigation: