I am trying to solve this problem. I am reading data from csv fiile which has the following columns:
id, name, price
So i use the following code to read the csv:
import sys
import csv as input
def readFile(path):
try:
finput = input.reader(open(path,'rb'),delimiter=',',quotechar='|')
except IOError as (errno,strerror):
print "I/O error({0}): {1}".format(errno,strerror)
except:
print "Unexpected Error: ",sys.exc_info()[0]
raise
# covert format into list
fmod = list(finput)
return fmod
but the problem is the name field can be like
name, item_det now that " , " creates a trouble for me.. instead of reading the name field as a single entity having a comma in the description.. it splits that particular field. How do I solve this. Thanks
|name, item_det|, other_field, another_field(since you setquotechar='|'). The CSV module can handle that. If not, you'll probably want to do like @MartinBeckett said and parse it manually, or check the length of the list and merge those two fields manually if necessary.quotechar='"'