Namedtuples: some unexpected inconveniences

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Apr 14 21:02:21 EDT 2017


Peter Otten wrote:

> PS: Personally I would probably take the opposite direction and use dicts 
> throughout...

Yes, my suggestion to used namedtuples in the first place was
based on the assumption that you would mostly be referring to
fields using fixed names. If that's not true, then using
namedtuples (or a mutable equivalent) might just be making
things harder.

If the names are sometimes fixed and sometimes not, then
you have a tradeoff to make.

In the code you posted most recently, the only fixed field
reference seems to be row.title, and that only appears once.
So as long as that's all you want to do with the rows,
storing them as dicts would appear to be a clear winner.

-- 
Greg


More information about the Python-list mailing list