Create and Read CSV File

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

CREATE AND READ CSV FILE

import csv
with open('scores.csv','w')as fp:
a=csv.writer(fp,delimiter=',')
data=[['Name','Age'],['Arjun','10'],['Ramya' ,'15'],['Sri','2']]
a.writerows(data)
fp.close()
print("csv file created")
print("content of the csv file")
with open("scores.csv","r")as scoreFile:
scoreFileReader=csv.reader(scoreFile)
scorelist=[]
for row in scoreFileReader:
if len(row)!=0:
scorelist=scorelist+[row]
scoreFile.close()
print(scorelist)

OUTPUT:

csv file created


content of the csv file
[['Name', 'Age'], ['Arjun', '10'], ['Ramya', '15'], ['Sri', '2']]
>>>

You might also like