Cleaning up conditionals

Gregory Ewing greg.ewing at canterbury.ac.nz
Mon Jan 2 18:27:53 EST 2017


Deborah Swanson wrote:
> flds = len(ls[0])
> cl, ur, d1, de, lo, st, mi, ki, re, da, br, no, yn, ma, ar =
> range(0,flds)

You might like to consider converting the row into a
namedtuple, then you could refer to the fields using
attribute names instead of indexes.

You could even use the header row to set up the field
names in the namedtuple, so if you reorder the columns
in the file, the code would automatically adapt.

-- 
Greg



More information about the Python-list mailing list