w3ajay

tally tutorial point, ms word 2013, ms excel 2013, ms powerpoint 2010,ccc question with answer in hindi 2021, Tally Prime in hindi , tally prime,Python,in python,programming in python,python

Sunday, August 18, 2024

Program for write in csv file class 12

 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()



Output

Thanks for visiting my blog 


1 comment:

for more information please share like comment and subscribe