DEV Community

I'm Just a Guy with a Computer
I'm Just a Guy with a Computer

Posted on

Writing data to CSV file in python using Writer object.

A Writer object lets you write data to a CSV file, To create a a writer object, you use the csv.writer() function.Enter the following code below into interactive shell and get to understand it .

import csv

outputFile = open('output.csv', 'w', newline='')
outputWriter = csv.writer(outputFile)
outputWriter.writerow(['kenya', 'Uganda', 'Tanzania', 'Ethiopia'])

outputWriter.writerow(['Javascript','python','php','kotlin','vb'])
outputWriter.writerow([1, 2, 3.141592, 4])


outputFile.close()
Enter fullscreen mode Exit fullscreen mode

call open() and pass it 'w' to open a file in write mode u. This will create the object you can then pass to csv.writer() v to create a Writer object and finally output.close will prevent the file for further execution.

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up