Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



I would also add

    __slots__ = ()
to your class definition so that instances of Foo keep the small memory footprint benefits do namedtuple.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: