[Python-ideas] Fwd: Anonymous namedtuples

Guido van Rossum guido at python.org
Tue Apr 19 11:06:30 EDT 2016


On Tue, Apr 19, 2016 at 4:49 AM, Chris Angelico <rosuav at gmail.com> wrote:

> Fortunately it isn't hard to create a namedtuple factory:
>
> def NS(fields):
>     return namedtuple('anonymous', fields.split())
>
> or possibly:
>
> def NS(fields, *values):
>     return namedtuple('anonymous', fields.split())(*values)
>
> That cuts down the duplication some, but it's far from perfect.
>

Please don't recommend or spread this idiom!

Every call to namedtuple() creates a new class, which is a very expensive
operation. On my machine the simplest namedtuple call taks around 350 usec.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160419/1613c62e/attachment-0001.html>


More information about the Python-ideas mailing list