Computer Science - Class 12
Chapter 2 - File Handling in Python

Explain Reading CSV files with CSV.

 

Answer:

CSV files are handled using the csv module. The reader class from the module is used for reading from a csv file .

  • At first, the csv file is opened in the read mode using the in-built function open( ).
  • The open( ) function returns a file object.
  • This file object is passed to the reader.

Example:

import csv

f=open( "values.csv" , 'r' )

output=csv.reader(f,delimiter= ',' )

for row in output:

    print(row)

 

 

 

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo