Possible Duplicate:
How to read a CSV line with "?
I have seen a number of related questions but none have directly addressed what I am trying to do.
I am reading in lines of text from a CSV file.
All the items are in quotes and some have additional commas within the quotes.
I would like to split the line along commas, but ignore the commas within quotes.
Is there a way to do this within Python that does not require a number of regex statements.
An example is:
"114111","Planes,Trains,and Automobiles","50","BOOK"
which I would like parsed into 4 separate variables of values:
"114111" "Planes,Trains,and Automobiles" "50" "Book"
Is there a simple option in line.split() that I am missing ?
If you want to read lines from a CSV file, use Python’s
csvmodule from the standard library, which will handle the quoted comma separated values.Example