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()
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)