[Python] Tuple not writing into a CSV file properly

Discussão em 'Python' iniciado por Stack, Agosto 25, 2025.

  1. Stack

    Stack Membro Participativo

    I have a tuple like:

    ('so glad', 'happy')
    ('it is so sad', 'sad')


    I want to write these tuples into a CSV file like:

    column1 column2
    so glad happy
    it is so sad sad


    I used following code to do this:

    with open('test.csv', "a") as outfile:
    for entries in my_list:
    outfile.write(entries)
    outfile.write("\n")


    But it writes into the CSV file as

    column1
    so glad
    happy
    it is so sad
    sad


    How can I make this code do as I expected?

    Continue reading...

Compartilhe esta Página