3 ms·
Yes Python code is often crying out for names better than [0] and [1]. And the big problem with namedtuples is that definition is so heavyweight - requires a n
by mhneu 8y ago
Yes Python code is often crying out for names better than [0] and [1].
And the big problem with namedtuples is that definition is so heavyweight - requires a new line of code, a new class object, picking the scope for that class (top-level means you have to keep track of your nonlocal definition), and namedtuples often block pickling.
I use argparse.Namespace but it has some memory issues namedtuple was invented to solve.
You can use a pandas series which has advantages, esp with many similar objs, but brings a new dependency and has some of the definitional problems.
Python is crying out for a lightweight namedtuple for this purpose.
- heavenlyblue 8y agoJust use typing.NamedTuple.
- mhneu 8y agoThat has the same problems with the extra class definition: extra lines of code, choice of scope to define the new class, and maybe issues with pickling.