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
CSV is exactly that: “Comma Separated”. You either need to quote the name field:
Or use an escape character, but you have to turn it on by setting quoting to QUOTE_NONE:
Example:
Otherwise, don’t use the csv module.