[Python] Write CSV file with double quotes for particular column not working

Discussão em 'Python' iniciado por Stack, Dezembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to write a CSV file using Python's csv writer.

    One of the column values is enclosed in "" [double quotes] e.g.: 'col1' 'col2' "test". When I open the file in Wordpad, the word test is expected as "test" but the actual result is """test""".

    Can someone please guide for this issue?

    Sample snippet of my try out:

    csvReader = csv.reader(iInputFile)
    writer = csv.writer(open('one_1.csv', 'wb'), delimiter=',', lineterminator='\r\n')

    for row in csvReader:
    rawRow = []
    rawRow.append('31-7-2014') #Appending Date
    rawRow.append(row[0]) #Appending data
    rawRow.append('\"'+'test'+'\"')
    writer.writerow(rawRow)

    Continue reading...

Compartilhe esta Página