Python Parse CSV Correctly
Posted
by
cornerstone
on Stack Overflow
See other posts from Stack Overflow
or by cornerstone
Published on 2012-09-06T09:04:41Z
Indexed on
2012/09/06
9:38 UTC
Read the original article
Hit count: 226
I am very new to Python. I want to parse a csv file such that it will recognize quoted values - For example
1997,Ford,E350,"Super, luxurious truck"
should be split as
('1997', 'Ford', 'E350', 'Super, luxurious truck')
and NOT
('1997', 'Ford', 'E350', '"Super', ' luxurious truck"')
the above is what I get if I use something like str.split().
How do I do this? Also would it be best to store these values in an array or some other data structure? because after I get these values from the csv I want to be able to easily choose, lets say any two of the columns and store it as another array or some other data structure.
Thanks in advance.
© Stack Overflow or respective owner