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

Mark Hackett mark.hackett at metoffice.gov.uk
Wed Jan 30 11:32:54 CET 2013


On Tuesday 29 Jan 2013, Eric V. Smith wrote:

On 1/29/2013 3:37 PM, Stephen J. Turnbull wrote: > Eric V. Smith writes: > > True. But my point stands: it's possible to read the data (even with a > > DictReader), do something with the data, and not know the column names > > in advance. It's not an impossible use case. > > But it is. Dicts don't guarantee iteration order, so you will most > likely get an output file that not only has a different delimiter, but > a different order of fields.

We're going to have to agree to disagree. Order is not always important.

It's not impossible that we're living in a simulated world.

If you don't know what's in the csv file at all, then how do you know what you're supposed to do with it.

Reading into a list will ensure order, so that is usable if order is important. If the names aren't important at all, then you should drop the first line and read it into a list again. If the names are important, you'd better know what names the headers are using.



More information about the Python-ideas mailing list