Steven, (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 type. Your sketch of a solution convinced me it can be done with a library function; no additional syntax needed. Cheers, On Tue, Jul 25, 2017 at 5:08 AM, Stephen J. Turnbull < turnbull.stephen...@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), > 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: turnb...@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@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Juancarlo *Añez*
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/