Page 139 - PYTHON-12
P. 139

The solution to the above problem is CSV (Fig. 4.3(b)). Thus, the CSV organizes data into a structured
               form and, hence, the proper and systematic organization of this large amount of data is done by
               CSV. Since CSV files formats are of plain text format, it makes it very easy for website developers to
               create applications that implement CSV.






















                                                   Fig. 4.3(b): CSV as a Solution


               CSV files are commonly used because they are easy to read and manage, small in size, and fast
               to  process/transfer.  Because  of  these  salient  features,  they  are  frequently  used  in  software
               applications, ranging anywhere from online e-commerce stores to mobile apps to desktop tools.
               For example, Magento, an e-commerce platform, is known for its support of CSV.

               Thus, in a nutshell, the several advantages that are offered by CSV files are as follows:
               •  CSV is faster to handle.

               •  CSV is smaller in size.
               •  CSV is easy to generate and import onto a spreadsheet or database.

               •  CSV is human readable and easy to edit manually.
               •  CSV is simple to implement and parse.

               •  CSV is processed by almost all existing applications.
               After understanding the concept and importance of using CSV files, we will now discuss the read
               and write operations on CSV files.

               4.15 CSV FILE HANDLING IN PYTHON


               For working with CSV files in Python, there is an inbuilt module called CSV. It is used to read and
           Computer Science with Python–XII  4.10 CSV module can handle CSV files correctly regardless of the operating system on which the files
               write tabular data in CSV format.
               Therefore,  to  perform  read  and  write  operation  with  CSV  file,  we  must  import  CSV  module.


               were created.

               Along with this module, open() function is used to open a CSV file, and return file object. We load
               the module in the usual way using import:
                 >>> import csv
   134   135   136   137   138   139   140   141   142   143   144