4 ms·
Attrs (https://attrs.readthedocs.io/ https://attrs.readthedocs.io/) replaced namedtuple for us (and many others). It's slightly more verbose but allows all clas
by jonasvp 10y ago
Attrs (https://attrs.readthedocs.io/ https://attrs.readthedocs.io/) replaced namedtuple for us (and many others). It's slightly more verbose but allows all class goodness such as methods, attribute validation, etc.
- justinsaccount 10y agoDoesn't work for everything, but you can subclass a namedtuple: from collections import namedtuple class Foo(namedtuple("Foo", "a b c")): @property def sum(self): return self.a + self.b + self.c f = Foo(1,2,3) print f.sum
- brianwawok 10y agoThat doesn't look super awesome to me. I.e. classes or attrs both seem better.
- deleted 10y ago[deleted]
- foxylad 10y agoAaaaaarrrrrgggggh! I've had that particular itch for every one of my ten years with python, and at last I get to scratch it! Thanks so much for bringing it up.