[Csv] csv module generating an invalid line?
Skip Montanaro
skip at pobox.com
Thu Jan 20 22:04:13 CET 2005
We use the csv module in the SpamBayes project as an interchange format (*).
It's generating, in part, a file like this:
...
simplymaya,0,1
entitled,1,1
"subject:
",0,1
depression.,1,0
...
Note the CR inside the quoted field (third line). When I try to read that
file, blammo! This example consists of a junk.csv file with just the above
four lines:
>>> for row in csv.reader(open("junk.csv")):
... print row
...
['simplymaya', '0', '1']
['entitled', '1', '1']
Traceback (most recent call last):
File "<stdin>", line 1, in ?
Error: newline inside string
I think one way or the other the csv module is broken. Either it should be
able to read this csv file or it should somehow generate it differently.
I've confirmed this with Python from CVS (as of Jan 5 05), the 2.4
maintenance branch (as of Dec 26 04) and Python 2.3.4.
Thoughts?
Skip
* See the sb_dbexpimp.py script:
http://cvs.sourceforge.net/viewcvs.py/spambayes/spambayes/scripts/sb_dbexpimp.py?rev=1.17&view=log
The above has this import:
try:
import csv
# might get the old object craft csv module - has no reader attr
if not hasattr(csv, "reader"):
raise ImportError
except ImportError:
import spambayes.compatcsv as csv
Note that I am getting the Python-sourced csv file, not the compatibility
module that's part of the SpamBayes code.
More information about the Csv
mailing list