Error while using QUOTE_NONE to never quote fields while writing to csv

a 夏天 提交于 2019-12-11 10:43:05

问题


I've written a simple code in python using xlrd module that reads data from xlsx file and writes it to csv. When I try to write to csv with no fields I'm getting below error:

Error: need to escape, but no escapechar set

with reference to question 23296356 on so, I've tried setting quotechar to empty string to fix the error.But that did not fix the issue. What I'm I missing here? Below the code snippet that I've be running:

import xlrd
import csv
wb=xlrd.open_workbook('testfile.xlsx')
lisT = wb.sheet_names()
lLength = len(lisT)
for i in range(0,lLength-1):   
     sh = wb.sheet_by_name(lisT[i])
     shfile = lisT[i]+".csv"
     csvoutfile = open(shfile,'wb')
     wr = csv.writer(csvoutfile, quoting=csv.QUOTE_NONE, quotechar='') #facing the issue here    

     for rownum in xrange(sh.nrows):
        wr.writerow(sh.row_values(rownum))
     csvoutfile.close()

来源:https://stackoverflow.com/questions/36277973/error-while-using-quote-none-to-never-quote-fields-while-writing-to-csv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!