Re:Grumpy: Go running Python
by jonasvp on Wednesday January 04, 2017 @02:40PM
(#13321367)
Attrs (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.
[ Parent
| on HN ]
Re:Grumpy: Go running Python
by justinsaccount on Wednesday January 04, 2017 @02:53PM
(#13321472)
Doesn'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
Re:Grumpy: Go running Python
by brianwawok on Wednesday January 04, 2017 @03:34PM
(#13321807)
That doesn't look super awesome to me. I.e. classes or attrs both seem better.