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

Thursday, August 15, 2024

what is csv file in python class 12



 what is csv file in python class 12

CSV stands for Comma Separated Value. CSV is a file in which DATA is stored in Tabular format i.e. Row and Column. It has extension " .csv  ". The Values are separated  by Comma ( , ).

  

CSV Module

The CSV Module  of python provides functionality to Write and Read tabular data in CSV format. It provides two specific types of object the writer and reader object.

       ex:- import csv  


File opening Mode:

1. r  Mode:

                1- Read Mode
                2- Default Mode
                3- Cursor is present at the top
                4- It will give error if the file not found 

2. w Mode:

                1- Write mode
                2- Always create a new file 
                3-  Cursor(file handle) is present at the top
                4- if same file is created then it will be delete it and will create a new file 

3. a Mode:

               1- append Mode
               2- Opens the file and preserves previous contents 
               3-  Cursor(file handle) is present at the last 
                4- if the file not present then it opens a new blanks file 

4. r+  -------read and write

5. w+  ----------write and read

6- a+   ----------- append and read

A Role of Argument newline in Opening of csv Files

While opening csv files, in the open(), you can specify an additional argument newline, which is an optional but important argument. The role of newline argument is to specify how would Python handle newline characters while working with csv files.

Additional optional argument as newline = " (null string; no space in between) with file open( ) will ensure that no translation of end of line (EOL) character takes place.

With open as function  
if you are using with open as function it is not required to close file with close function

writing in csv file   

  1. csv.writer()
  2. <writerobject>.writerow()
  3. <writerobject>.writerows()


  1. csv.writer()
            returns a writer object which writes data into CSV file

2.<writerobject>.writerow()

        writes one row of data onto the writer object

3.<writerobject>.writerows()

        writes multiple rows of data onto the writer object



No comments:

Post a Comment

for more information please share like comment and subscribe