[Python-Dev] Py2.6 ideas (original) (raw)
Michele Simionato michele.simionato at gmail.com
Tue Feb 20 09:52:53 CET 2007
- Previous message: [Python-Dev] Py2.6 ideas
- Next message: [Python-Dev] Py2.6 ideas
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Raymond Hettinger <python rcn.com> writes:
More thoughts on named tuples after trying-out all of Michele's suggestions: * The lowercase 'namedtuple' seemed right only because it's a function, but as a factory function, it is somewhat class-like. In use, 'NamedTuple' more closely matches my mental picture of what is happening and distinguishes what it does from the other two entries in collections, 'deque' and 'defaultdict' which are used to create instances instead of new types.
This is debatable. I remember Guido using lowercase for metaclasses in the famous descrintro essay. I still like more the lowercase for class factories. But I will not fight on this ;)
* I remembered why the repr function had a 'show' argument. I've changed the name now to make it more clear and added a docstring. The idea was the some use cases require that the repr exactly match the default style for tuples and the optional argument allowed for that possiblity with almost no performance hit.
But what about simply changing the repr?
In [2]: Point = NamedTuple('Point','x','y')
In [3]: Point(1,2) Out[3]: Point(x=1, y=2)
In [4]: Point.repr = tuple.repr
In [5]: Point(1,2) Out[5]: (1, 2)
It feels clearer to me.
Michele Simionato
- Previous message: [Python-Dev] Py2.6 ideas
- Next message: [Python-Dev] Py2.6 ideas
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]