write csv file with double quotes for particular column not working

前端 未结 3 1468
执念已碎
执念已碎 2021-01-11 16:43

I\'m trying to write a csv file using python csv writer.

In which one of the column value is enclosed in \"\" [double quotes] e.g. : \'col1\' \'col2\' \"test\", when

3条回答
  •  庸人自扰
    2021-01-11 17:31

    try with this one

    f_writ = open('one_4.csv', 'wb')
    csvReader = csv.reader(iInputFile)
    writer = csv.writer(f_writ, delimiter=',',
                    lineterminator='\r\n',
                    quotechar = "'"
                    )
    
    for row in csvReader:
    
        writer.writerow(['31-7-2014',row[0],'\"text\"'])
    
    f_writ.close()
    

    also i find very useful this link http://pymotw.com/2/csv/, there are a lot of exemples

提交回复
热议问题