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

Eric V. Smith eric at trueblade.com
Tue Jan 29 19:49:01 CET 2013


On 01/29/2013 07:35 AM, Mark Hackett wrote:

On Tuesday 29 Jan 2013, Steven D'Aprano wrote:

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.

You cannot assume that the caller knows that there are duplicated column names You cannot assume they wanted them as a list. You cannot assume that duplicate replacement is what they want. If someone is using a csv file with header names they have never read, how are they going to use the data? They won't even know the name to access the value in the dictionary! So I discard the claim that the caller may not know the column names are duplicated. They have to know what the headers are to use DictReader.

Not true: I process some csv files just to translate them into another format, say tab delimited. I don't care about the column names, but dropping columns would sure bother me. I don't think any of the files I've processed have duplicate columns, but I wouldn't swear to it. And if they did, that would be an error I'd like to know about.

Eric.



More information about the Python-ideas mailing list