Issue 5332: csv sniffer - Python tracker (original) (raw)

Issue5332

Created on 2009-02-20 20:45 by LambertDW, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
csv.diff skip.montanaro,2009-02-26 03:32
Messages (3)
msg82546 - (view) Author: David W. Lambert (LambertDW) Date: 2009-02-20 20:45
Following instructions in http://docs.python.org/dev/3.0/library/csv.html#module-csv I opened file in binary mode. This might be simply a documentation problem or it may run deeper. Text mode works on red hat linux system. Here's the use: >>> stream=open('csv','rb') >>> dialect=csv.Sniffer().sniff(stream.read(1024)) Traceback (most recent call last): File "", line 1, in File "/usr/users/lambert/bin/python/lib/python3.0/csv.py", line 169, in sniff self._guess_quote_and_delimiter(sample, delimiters) File "/usr/users/lambert/bin/python/lib/python3.0/csv.py", line 210, in _guess_quote_and_delimiter matches = regexp.findall(data) TypeError: can't use a string pattern on a bytes-like object Here's the conflicting documentation statement: "If csvfile is a file object, it must be opened with the ‘b’ flag on platforms where that makes a difference. ... see section Dialects and Formatting Parameters. All data read are returned as strings. No automatic data type conversion is performed." (Problem is that the binary file returnd data of type bytes.) Thanks, Dave.
msg82740 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2009-02-26 03:32
I verified the bug. I started to work on a patch (see attached), but it quickly seems to get out-of-hand with tracebacks about stuff not supporting the buffer API. I suspect the real solution might involve doing something to convert the bytes to strings read when in binary mode, but I don't have any idea how to finesse the requirement of bytes() for an encoding arg.
msg106212 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-05-21 01:40
This is in fact a doc bug. The correct way to read a csv file in python3 is to open it in text mode with newline=''. The docs have been updated to reflect this.
History
Date User Action Args
2022-04-11 14:56:46 admin set github: 49582
2010-05-21 01:40:42 r.david.murray set status: open -> closednosy: + r.david.murraymessages: + resolution: out of datestage: needs patch -> resolved
2010-05-20 20:27:43 skip.montanaro set nosy: - skip.montanaro
2009-02-26 03:32:16 skip.montanaro set files: + csv.diffversions: + Python 3.1nosy: + skip.montanaromessages: + keywords: + patchstage: needs patch
2009-02-20 20:45:32 LambertDW create