[issue26737] csv.DictReader throws generic error when fieldnames is accessed for non-text file

Josh Rosenberg report at bugs.python.org
Mon Apr 11 21:52:37 EDT 2016


Josh Rosenberg added the comment:

This already behaves usefully in 3.5 where reading fieldnames from a DictReader wrapping a file opened in binary mode gets you:

_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)

And 2.7 is highly unlikely to make fit and finish fixes at this stage in the game.

That said, not sure what you'd expect in 2.7; standard open in binary mode is correct there, and you'd get str either way. Is the problem that it's not a CSV file in the first place? Because Python 2's csv isn't encoding aware; as long as it doesn't have embedded NULs, anything could be legitimate data (csv doesn't have the context to say that it should be latin-1, EBCDIC, or whatever).

----------
nosy: +josh.r

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26737>
_______________________________________


More information about the Python-bugs-list mailing list