CSV Files-Notes (1)
CSV Files-Notes (1)
CSV Files-Notes (1)
Advantages:
Easier to create.
Mostly used for importing & exporting data to and from the database.
Capable of storing large amount of data.
CSV Module
CSV module provides 2 objects:
1) writer: to write in to the CSV files
2) reader: to read data from the CSV files.
To import CSV module in our program, write the following statement:
import csv or from csv import *
Opening a CSV files:
f=open(“student.csv”,”w”) # open file in the write mode and newline
argument is optional by default its value is
‘\n’.
‘’:null string indicates no space in between.
OR
f=open(“student.csv”,”r”) # open file in a read mode.
Closing of CSV files:
f.close()
Writing in CSV files
csv. writer() Returns a writer object
which writes data in to csv
files.
<writer_object>. Writes one row of data on to
writerow() writer object.
<writer_object>. Writes multiple rows on to the
writerows() writer object.