Error while using QUOTE_NONE to never quote fields while writing to csv
Asked Answered
T

0

1

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()
Treat answered 29/3, 2016 at 7:26 Comment(4)
What data are you writing, can you share a sample?Clarhe
Below is the file that I'm directly working on: onedrive.live.com/…Treat
Please put a sample in your question. You don't need the excel reading part, for example, to reproduce your problem. Just use print(sh.row_values(rownum)) for the first few rows, put those in a list, and add those to your question. Do test that the rows you add to your question actually reproduce the problem. If you add expected output too you'd have a complete minimal reproducible example.Clarhe
It's probably a new line characterDetour

© 2022 - 2024 — McMap. All rights reserved.