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

J. Cliff Dyer jcd at sdf.lonestar.org
Wed Jan 23 22:13:54 CET 2013


On Wed, 2013-01-23 at 14:59 -0500, Jerry Hill wrote:
> > However, since python is mechanising this as a dictionary and since
> in python
> > setting A to 1 then setting A to 3 would throw away the earlier
> value for A
> > and the import function working AS EXPECTED in Python.
> 
> I'm not sure this behavior merits the all-caps "AS EXPECTED" label.
> It's not terribly surprising once you sit down and think about it, but
> it's certainly at least a little unexpected to me that data is being
> thrown away with no notice.  It's unusual for errors to pass silently
> in python. 

Moreover, I think while it might be expected for a dict to do this, it
does not follow that a DictReader should be expected to silently throw
away the user's data.  Just because it uses the dict format for storage
does not mean that it's okay to throw away user's data silently.  Dicts
need to be blazingly fast for a host of reasons.  DictReaders do not.
They're usually dealing with file input, so any slowness in the
DictReader itself is going to be dwarfed by the file access.  As such we
can afford to be more programmer-friendly here.

Cheers,
Cliff






More information about the Python-ideas mailing list