3 ms·
First para: I think maybe you're confusing 'class' with inheritance from 'object'. A good tip is to do: class Foo(namedtuple('Foo', (...)): def __r
by sago 10y ago
First para: I think maybe you're confusing 'class' with inheritance from 'object'. A good tip is to do:
class Foo(namedtuple('Foo', (...)):
def __repr__(self):
...
Your 'Foo' gets ordering, hashing, comparison, because it derives from 'namedtuple'. It gets '__repr__' too, but in the example I'm overriding that.
- throwaway274739 10y agoI would also add __slots__ = () to your class definition so that instances of Foo keep the small memory footprint benefits do namedtuple.