I am parsing a poorly written csv
file with Python and am wondering, is there a way to have more than one quote character in Python's csv.reader
?
For example, my file looks like this:
somedata, "some other data which is a string", [1,2,3,4]
moredata, "more data which may have commas ,", [12]
What I want is to do something like this:
import csv
with open('myfile.csv') as f:
r = csv.reader(quotechar='"', delimiter=',', bracketchar='[]')
for row in r:
print row[0]
Which would result in something like
['1', '2', '3', '4']
['12']
or at the very least something similar. I can, of course, do this by simply reading the file, but I feel like the csv
module might enable a more elegant solution...