[Python-ideas] csv.DictReader could handle headers more intelligently.

Alexandre Zani alexandre.zani at gmail.com
Tue Jan 29 02:15:22 CET 2013


I think raising an exception on duplicate headers is actually very likely
to cause working code to break. Consider that all you need for that to
happen is an extra couple of empty separators on the first line creating
two "" headers. That seems like the sort of behavior that is easy to occur
in spreadsheet programs. (Empty cells are usually not very well
differentiated from non-existent cells in spreadsheet UIs IME) A
StrictDictReader is better, but I think this is overkill.

As for a MultiDictReader, I don't think this is superior to csv.reader. In
both cases, you need to keep track of the column orders. And if you already
know the column order, you might as well just manually specify the field
names in DictReader.


On Mon, Jan 28, 2013 at 4:01 PM, Bruce Leban <bruce at leapyear.org> wrote:

> The reader could return a multidict. If you know it's a multidict you an
> access the 'discarded' values. Otherwise, it appears just like the dict
> that we have today. A middle ground between people that don't want the
> interface changed and those who want to get the multiple values.
> Personally, I prefer code that raises exceptions when it gets unreasonable
> input, and I think duplicate field names qualifies. But if that's the the
> general sentiment than a multidict is a potential compromise.
>
> --- Bruce
> Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130128/3c757462/attachment.html>


More information about the Python-ideas mailing list