python - CSV remove field value wrap quotes -


i'm attempting write list csv, when wrapper quotes around field values:

number1,number2 "1234,2345" "1235.7890" "2345.5687" 

using code:

with open('c:\\temp\\test.csv', 'wb') out_file: ... csv_writer = csv.writer(out_file, delimiter=',') ... csv_writer.writerow(('number1','number2')) ... f in mylist: ... csv_writer.writerow(f) 

after further research, found can remove writing of quotes using:

quotechar='', quoting=csv.quote_none**

when apply code error:

traceback (most recent call last): file "", line 4, in error: need escape, no escapechar set

with open('c:\\temp\\test.csv', 'wb') out_file: ... csv_writer = csv.writer(out_file, delimiter=',',quotechar='', quoting=csv.quote_none) csv_writer.writerow(('number1','number2')) ... f in mylist: ... csv_writer.writerow(f) 

how remove these quotes?

edit

mylist looks like:

 [['1234,2345'], ['1235,7890'], ['2345,5687']] 

what's in list not numbers text, containing delimiter character. means export csv has escaped.

you need convert data numbers before export csv if want written correctly.

edit: on other hand data looks consits of comma separated values - why not write file directly without using csv writer?


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -