Computer Science

Identify the error in the following code.

import csv
f = open('attendees1.csv')
csv_f = csv.writer(f)

Python File Handling

2 Likes

Answer

import csv
f = open('attendees1.csv') #error
csv_f = csv.writer(f)

To use the csv.writer() function, the file should be opened in write mode ('w'). The corrected code is :

import csv
f = open('attendees1.csv', 'w')
csv_f = csv.writer(f)

Answered By

1 Like


Related Questions