Write Data to CSV File using Python

csv module

import csv

data = [
    ['John', 25],
    ['Mary', 30],
    ['Robert', 42],
]

with open('test.csv', mode='w', newline='') as file:
    csvWriter = csv.writer(file)

    for item in data:
        csvWriter.writerow(item)

Leave a Comment

Cancel reply

Your email address will not be published.