[Python-ideas] csv.DictReader could handle headers more intelligently.
Yuval Greenfield
ubershmekel at gmail.com
Wed Jan 23 22:54:05 CET 2013
On Wed, Jan 23, 2013 at 11:13 PM, J. Cliff Dyer <jcd at sdf.lonestar.org>wrote:
>
> 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.
>
If it were a NamedTupleReader, this wouldn't be an issue.
>>> from collections import namedtuple
>>> namedtuple('x', 'a b a c')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
namedtuple('x', 'a b a c')
File "C:\Python27\lib\collections.py", line 288, in namedtuple
raise ValueError('Encountered duplicate field name: %r' % name)
ValueError: Encountered duplicate field name: 'a'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130123/c0c880bc/attachment.html>
More information about the Python-ideas
mailing list