We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8
CSV FILES
CSV stands for comma separated values.
CSV is just like a txt file, in a human readable format which is extensively used to store tabular data , in a spreadsheet or database. The separator character of CSV files is called a delimiter. Default delimiter is comma(,),other delimiters are tab(‘\ t’),colon(:),pipe(|),semicolon(;) characters. Each line of a file is a record. Each record consists of fields separated by commas(delimiter) ADVANTAGES OF CSV FILES Easier to create. Preferred import and export format for databases and spreadsheets. Capable of storing large amount of data. CSV is faster to handle CSV is smaller in size CSV is easy to generate CSV is human readable and easy to edit manually CSV is simple to implement and parse CSV is processed by almost all existing applications. DISADVANTAGES OF CSV FILES No standard way to represent binary data. There is no distinction between text and numeric values. Poor support of special characters and control characters CSV allows to move most basic data only. Complex configurations cannot be imported and exported this way. Problems with importing CSV into SQL(no distinction between NULL and quotes) PYTHON CSV MODULE CSV module provides two type of objects: 1. Reader- to read from the csv files. 2. Writer- to write in to the csv files. To import csv module in our program , write the following statement: import csv OPENING / CLOSING CSV FILES Open a csv files: f=open(“stu.csv”,”w”) or f=open(“stu.csv”,”r”) Close a csv files: f.close() ROLE OF ARGUMENT NEWLINE IN OPENING OF CSV FILES
o Newline argument specifies how would python handle new line characters while working with csv files, on different operating systems. o Different operating systems store EOL characters differently.
Symbol/Char Meaning Operating System
CR[\r] Carriage Return Macintosh
LF[\n] Line Feed UNIX
CR/LF[\r \n] Carriage Return/ MSDOS , windows
Line Feed NULL[\0] NULL character Other OSs WRITING IN CSV FILES Csv .writer() Returnsa writer object which writes data into csv files
<writerobjject>.writerow() Writes one row of data on to the writer
object.
<writerobjject>.writerows() Write multiple rows of the writer object.
ROLE OF WRITER OBJECT The csv.writer() function returns a writer object that converts the user’s data into a dellimited string. This string can later be used to write into CSV files using the writerow() function or writerows() function .