What program to create CSV files?
To write data into a CSV file in Python, we use the csv. writer() function to create a writer object that can write data to the file. The writer object has methods like writerow() and writerows() that can write one or more rows of data to the fileTo write data into a CSV file in Python, we use the csv. writer() function to create a writer object that can write data to the file. The writer object has methods like writerow() and writerows() that can write one or more rows of data to the file
Program
#Program for write in csv file
import csv
fobj=open("ram.csv","w",newline='')
f=csv.writer(fobj)
data=['roll','name','marks']
f.writerow(data)
while True:
roll=int(input("Enter the roll no:"))
name=input("Enter the Name:")
marks=int(input("Enter the Marks:"))
data2=[roll,name,marks]
f.writerow(data2)
key=int(input("Press 1-> for Continue: \n Press 2-> for Stop:"))
if key==2:
break
fobj.close()
So Good
ReplyDelete