Namedtuples: some unexpected inconveniences
python at deborahswanson.net
Thu Apr 13 03:03:36 EDT 2017
Peter Otten wrote, on Wednesday, April 12, 2017 11:35 PM
> Deborah Swanson wrote:
> > It's a small point, but I suspect getattr(record, label)
> would still
> > fail, even if label's value is 'label' and only 'label', but what's
> > the point of having a variable if it will only ever have just one
> > value?
> You are misunderstanding. Your getattr() call fails because you have
> label = "label"
> burried somewhere in your code. As soon as you change that to
> label = <insert an existing attribute name here>
> the error will go away.
Yes, the error goes away, but now getattr(record, label) is useless for
processing field names, unless you want to write a line of code for each
one. (I have 17 field names, and forget about passing label to a
More information about the Python-list