3 ms·
A class seems heavy. The tuple() is a great way to keep it light.
by smitty1e 5y ago
A class seems heavy. The tuple() is a great way to keep it light.
- teddyh 5y agoUse a named tuple. This way, you can turn it into a class if it ever becomes necessary without changing any other code.
- SethMLarson 5y agoI'd recommend dataclasses over namedtuples. In almost every case the "iterability" of a namedtuple ends up not being necessary (and can be a footgun!) what you really want is a lightweight namespace with types i.e. dataclasses!
- wheelerof4te 5y agoYes, but only for compound types with 3-4 values, maximum. If you need something to store 7-8 different value types, either make a class or reach for named tuple. I tried using regular tuples as lightweight objects, it does not work.