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

Shane Green shane at umbrellacode.com
Tue Jan 29 06:24:06 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.


Python-ideas mailing list Python-ideas at python.org http://mail.python.org/mailman/listinfo/python-ideas

Actually I've seen a many real life examples of CSV files with repeated column names, working with log data in the energy management space. CSV has been around for a very long time, and is used for a lot more than spreadsheets; there are a lot of funky formats out there. Things like, every "VALUE" column is a 15 minute reading. It seems like we're getting too hung up on dicts: all the information about a record is precisely stored by two sequences of values: the headers, and the field values. Those entires and their order can both be useful to a consumer of CSV records, and should be made available. The record also maps headers to corresponding value sequences for mapped access.
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130128/83f08f6a/attachment.html>



More information about the Python-ideas mailing list