[Python-ideas] A namedtuple literal.

Eric Snow ericsnowcurrently at gmail.com
Wed Apr 2 07:07:03 CEST 2014


On Tue, Apr 1, 2014 at 10:59 PM, Haoyi Li <haoyi.sg at gmail.com> wrote:
> I personally made my own "namedtuple" "literal"
>
> class Container:
>     pass
>
> def t(**kw):
>     c = Container()
>     for k, w in kw.items():
>         setattr(c, k, w)
>     return c
>
> t(color=c, position=p)

Nice!  Alas, you lose your kw order so it's less namedtuply, which is
precisely what I've been digging the list archives about. :)

-eric


More information about the Python-ideas mailing list