我试图写一个清单到CSV,但是当我这样做,我避开我的字段值包装报价:
number1,number2
"1234,2345"
"1235.7890"
"2345.5687"
使用此代码:
with open('C:\\temp\\test.csv', 'wb') as out_file:
... csv_writer = csv.writer(out_file, delimiter=',')
... csv_writer.writerow(('number1','number2'))
... for f in myList:
... csv_writer.writerow(f)
经过进一步研究,我发现,您可以通过使用去除引号的文字:
quotechar = '',引用= csv.QUOTE_NONE **
当我将此我的代码,我得到这个错误:
回溯(最近通话最后一个):文件“”,4号线,在错误:需要逃跑,但没有escapechar集
with open('C:\\temp\\test.csv', 'wb') as out_file:
... csv_writer = csv.writer(out_file, delimiter=',',quotechar='', quoting=csv.QUOTE_NONE)
csv_writer.writerow(('number1','number2'))
... for f in myList:
... csv_writer.writerow(f)
如何删除这些报价?
编辑
myList中的样子:
[['1234,2345'], ['1235,7890'], ['2345,5687']]