Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
teddyh
· 4y ago · 0 comments
Use a named tuple. This way, you can turn it into a class if it ever becomes necessary without changing any other code.
Comments
[–]
SethMLarson
4y ago
I'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!
[–]
teddyh
OP
4y ago
On the other hand, the immutability of a named tuple can be useful.
[–]
Marcan
4y ago
You can set frozen=True to make a dataclass immutable.