[Python-ideas] Add optional defaults to namedtuple

Joao S. O. Bueno jsbueno at python.org.br
Wed Nov 30 14:27:38 EST 2016


On 30 November 2016 at 13:09, Ethan Furman <ethan at stoneleaf.us> wrote:
> But even more readable than that is using the NamedTuple class from my aenum
> [3] library (and on SO as [3]):
>
> --> from aenum import NamedTuple
> --> class Node(NamedTuple):
> -->     val = 0
> -->     left = 1, 'previous Node', None
> -->     right = 2, 'next Node', None
>
> shamelessly-plugging-my-own-solutions'ly yrs,

Sorry - taking the boat to even-more-shamelessly anounce
extradict.extratuple.defaultnamedtuple - in the newly released

extradict v. 0.2.5

https://pypi.python.org/pypi/extradict/0.2.5

It allows one to build an default-paremetrized namedtuple by passing
a sequence of 2-tuples with key, values, or, on Python 3.6,
pass in the default values as keywords to the defaultnamedtuple factory.

(The  "extradict" package, with a faster reimplementation of
namedtuple already existed, of course - maybe someone can pick some other weird
idea I have into there to put it into more day-to-day use)

> --
> ~Ethan~


More information about the Python-ideas mailing list