Issue
I have a row of data that I am trying to write to a .tab file that looks like this:
row = ['07/19/2017/10/33/30', 'gg_ca_18" dishwashers_204454792491_1t1',
Decimal('369.00'), 1L, '66745355']
I want to leave the single quote not escaped so that it looks like this:
07/19/2017/10/33/30 gg_ca_18" dishwashers_204454792491_1t1 369.00 1 66745355
I am writing to a file using this code:
with open(file_name, 'wb') as outfile:
a = csv.writer(outfile, delimiter='\t') # ,escapechar=None, quoting=csv.QUOTE_NONE
a.writerows(row)
I have tried using escapechar=None, quoting=csv.QUOTE_NONE
and several variations of this. I always get the error Error: need to escape, but no escapechar set
. What is the best way to not escape the single quote in the middle of the line? Is it possible using csv
module?
Solution
You can just use a different quotechar
:
with open(file_name, 'w') as outfile:
a = csv.writer(outfile, delimiter='\t', quotechar="'")
a.writerow(row)
Answered By - Paulo Almeida
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.