csv-0.3 released
Skip Montanaro
skip at pobox.com
Mon Jun 18 17:42:21 EDT 2001
Chris> This appears to mean that the CSV parser is slower that
Chris> string.split, and as far as I can tell, does pretty much the same
Chris> thing. What am I missing?
CSV files can be syntactically more complex than simply inserting commas
between fields. For example, if a field contains a comma, it must be
quoted:
1,2,3,"I think, therefore I am",5,6
Also, you can quote fields (as above, but the quotes are not to be kept in
the parsed output. The above should yield
['1', '2', '3', 'I think, therefore I am', '5', '6']
Since fields are quoted using quotation marks, you also need a way to escape
them. This is usually done by doubling them:
1,2,3,"""I see,"" said the blind man","as he picked up his hammer and saw"
There are probably more rules, but the comma and quoting rules eliminate
simple string.split as a possibility. I believe the author was only using
his simple example as a bit of input that could be fed to both string.split
and csv.parser.
--
Skip Montanaro (skip at pobox.com)
(847)971-7098
More information about the Python-list
mailing list