0% found this document useful (0 votes)
44 views2 pages

Program 12

Uploaded by

rushda.7369
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views2 pages

Program 12

Uploaded by

rushda.7369
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PROGRAM-12

READ AND WRITE OPERATION IN CSV FILES


OBJECTIVE:
To write user defined functions to perform read and write operation onto a ‘student.csv’ file
having fields as roll_no, name and marks.

INPUT:
Read data from user

OUTPUT:
Display content of the file

CODING:
import csv
def WRITE():
f = open(“student.csv”, “w”, newline = “ ”)
csv_writer = csv.writer(f)
csv_writer.writerow([“Roll_no”, “Name”, “Marks”])
ans = “y”
while ans == “y”:
Rno = int(input(“Enter the roll number”))
name = input(“Enter the name”)
marks = int(input(“Enter the marks”))
sturec = [Rno, name, marks]
csv_writer.writerow(sturec)
ans = input(“Enter y to continue or n to exit”)
f.close()
def READ():
f1 = open(“student.csv”, “r”, newline = “ ”)
csv_read = csv.reader(f1)
for line in csv_read:
print(line)
f1.close()

RESULT:
The program was executed and output was obtained successfully.

You might also like