Page 4 - Lesson Note-DFH-Binary & CSV File
P. 4

#2.Reading from csv file
               import csv
               f=open("XI_SC_ANN.csv")
               recs=csv.reader(f)
               for L in recs:
                       for X in L:
                              print(X, end="\t")
                       print()
               f.close()

               #writing into csv file
               import csv
               f=open("Stud.csv", 'w')
               rec=csv.writer(f, delimiter=',')
               rec.writerow(['Adm', 'Name', 'Sec', 'Percentage', 'Stream'])
               while True:
                       Adm=int(input("Adm. number: "))
                       Name=input("Name: ")
                       Section=input("Section: ")
                       Percentage=float(input("Percentage: "))
                       Stream=input("Stream: ")
                       R=[Adm, Name.upper(), Section.upper(), Percentage, Stream.upper()]
                       rec.writerow(R)
                       ch=input("More Data??(Y/N) ")
                       if ch in 'yY':
                              continue
                       else:
                              break
                   f.close()
   1   2   3   4