[Python-ideas] csv.DictReader could handle headers more intelligently.
Mark Hackett
mark.hackett at metoffice.gov.uk
Wed Jan 23 19:32:20 CET 2013
On Wednesday 23 Jan 2013, Bruce Leban wrote:
> If there are duplicate column headers, they are probably there for a
> reason. I can't imagine a case where the desired result is to discard one
> of the columns. If DictReader is going to recognize this case, perhaps:
>
I can't see why there would be duplicate column headers for valid reason.
Someone may have written their CSV export incorrectly, but that's not actually
valid.
It would therefore be arguable for the program to give at least a WARNING that
it's throwing data away.
However, since python is mechanising this as a dictionary and since in python
setting A to 1 then setting A to 3 would throw away the earlier value for A
and the import function working AS EXPECTED in Python.
Hence a decorator to insist on some formatting issues (e.g. turning A into a
list of values 1,3 rather than throwing away the 1 or the 3). To do otherwise
would have someone in the official library have to write their own format
conversion and shove it in the middle and telling people what they should be
doing.
More information about the Python-ideas
mailing list