KnowledgeBoat Logo

Computer Science

Identify the error in the following code.

import csv
f = open('attendees1.csv')
csv_f = csv.reader()
for row in csv_f:
    print(row)

Python File Handling

3 Likes

Answer

import csv
f = open('attendees1.csv') #error 1
csv_f = csv.reader() #error 2
for row in csv_f:
    print(row)
  1. To use the csv.reader() function, the file should be opened in read mode ('r').
  2. The reader object should be in syntax <name-of-reader-object> = csv.reader(<file-handle>).

The corrected code is :

import csv
f = open('attendees1.csv', 'r')
csv_f = csv.reader(f)
for row in csv_f:
    print(row)

Answered By

2 Likes


Related Questions