[Python-ideas] namedtuple literals [Was: RE a new namedtuple]
apalala at gmail.com
Tue Jul 25 07:19:26 EDT 2017
(short of time here)
With **kwargs and a little more work, the function would check if the type
is already defined, and retur the ntuple with the correct type, not the
Your sketch of a solution convinced me it can be done with a library
function; no additional syntax needed.
On Tue, Jul 25, 2017 at 5:08 AM, Stephen J. Turnbull <
turnbull.stephen.fw at u.tsukuba.ac.jp> wrote:
> C Anthony Risinger writes:
> > At the end of the day, I don't see a way to have both a literal and
> > something that is externally "named", because the only ways to pass the
> > name I can imagine would make it look like a value within the container
> > itself (such as using a literal string for the first item), unless even
> > more new syntax was added.
> OK, so I took your "a tuple is a tuple is a tuple" incorrectly. What
> you want (as I understand it now) is not what
> def ntuple0(attr_list):
> return namedtuple("_", attr_list)
> gives you, but something like what
> def ntuple1(attr_list)
> return namedtuple("ImplicitNamedtuple_" + "_".join(attr_list),
> does. Then this would truly be a "duck-typed namedtuple" as Chris
> Barker proposed in response to Steven d'Aprano elsewhere in this
> thread. See also Nick's full, namedtuple-compatible, implementation.
> Of course we still have the horrible "list of strings naming
> attributes" argument, so you still want a literal if possible, but
> with a **key argument, a new builtin would do the trick for me. YMMV.
> Associate Professor Division of Policy and Planning Science
> http://turnbull/sk.tsukuba.ac.jp/ Faculty of Systems and Information
> Email: turnbull at sk.tsukuba.ac.jp University of Tsukuba
> Tel: 029-853-5175 Tennodai 1-1-1, Tsukuba 305-8573 JAPAN
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas