Cleaning up conditionals
Gregory Ewing
greg.ewing at canterbury.ac.nz
Mon Jan 2 22:57:56 EST 2017
Deborah Swanson wrote:
> Unless you know of, and are suggesting, a way to index a sequence with
> strings instead of integers, so the code could remain untouched with
> string indices when changes to the columns are made.
I'm talking about this:
https://docs.python.org/3/library/collections.html#collections.namedtuple
It's like a tuple, but the fields also have names, so
you can access them like attributes using dot-notation.
> Also, for such a scheme to be superior to what I already have, it needs
> to be very nearly self-maintaining.
If you derive the attribute names from the header row,
it would be extremely self-maintaining. You would be able
to reorder columns without touching the code at all.
--
Greg
More information about the Python-list
mailing list