[Python-ideas] csv.DictReader could handle headers more intelligently.
Mark Hackett
mark.hackett at metoffice.gov.uk
Tue Jan 29 14:44:35 CET 2013
On Tuesday 29 Jan 2013, Steven D'Aprano wrote:
> On 29/01/13 23:35, 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.
>
> I don't need to assume that. They can take the list and post-process it
> into any data type they want.
Yes you ARE assuming it. You want them to post process it. But if they don't
know there are duplicates there and have found their script works for their
needs and therefore never looked, they will now get the wrong answer.
As Oscar says, they could process the csv file themselves by hand and code in
EXACTLY what they want. They don't have to put it in a dictionary then.
And you've already said
> Then adding to a dictionary was a mistake.
So they shouldn't be using DictReader.
More information about the Python-ideas
mailing list