Differences creating tuples and collections.namedtuples

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Feb 18 09:53:39 EST 2013


On 18 February 2013 14:23, John Reid <j.reid at mail.cryst.bbk.ac.uk> wrote:
[snip]
> That said it would be nice to know the rationale for
> namedtuple.__new__ to have a different signature to tuple.__new__. I'm
> guessing namedtuple._make has a similar interface to tuple.__new__. Does
> anyone know what the rationale was for this design?

Because namedtuples use names for the arguments in the constructor:

>>> from collections import namedtuple
>>> Point = namedtuple('Point', 'x y')
>>> p1 = Point(x=2, y=3)
>>> p1
Point(x=2, y=3)
>>> p1.x
2


Oscar



More information about the Python-list mailing list