[Python-ideas] csv.DictReader could handle headers more intelligently. (original) (raw)

Mark Hackett mark.hackett at metoffice.gov.uk
Mon Jan 28 18:45:16 CET 2013


On Monday 28 Jan 2013, MRAB wrote:

It shouldn't silently drop the columns

Why not?

It's adding to a dictionary and adding a duplicate key replaces the earlier one.

If it dropped the columns and shouldn't have, then the results will be seen to be wrong anyway, so there's not a huge amount of need for this.

If it WANTED to keep both columns with the duplicate names, it won't work and needs abandoning. So no different from now.

If it WANTED duplicate keys (e.g. blanks which aren't imported and aren't wanted), then you've just broken it. They can't necessarily change the csv file to put headers in. So now you've made the call useless for this case.

And why, really, are there duplicate column names in there anyway? You can come up with the assertion that this might be wanted, but they're not normally what you see in a csv file.

I've never seen nor used a csv file that duplicated column names other than being blank.

If it had been such a problem, the call would already have been abandoned.



More information about the Python-ideas mailing list