1.

Write a Python program to read a CSV file with default delimiter comma (,)?

Answer»

CSV file with default delimiter comma(,) The following program read a file called “sample l.csv” with default delimiter cpmma(,) and print row by row.

#importing csv

import csv

#opening the csv fde which is in different location 

with read mode with open(‘c:\ \pyprg\\sample l.csv’ , V) as F:

#other way to open the file is f = (‘c:\\pyprg\\sample l.csv’ , ‘r’)

reader = csv.reader(F)

Sprinting each line of the Data row by row print(row) 

F.close( )

OUTPUT

[‘SNO’ , ‘NAME’ , ‘CITY’]

[12101’ , ’RAM’ , ‘CHENNAI’]

[‘12102′, ’LAVANYA’ , ’TIRUCHY’]

[‘12103′, ’LAKSHMAN’ , ’MADURA’]



Discussion

No Comment Found