-
Book Overview & Buying
-
Table Of Contents
Web Development with Django
By :
The csv module from Python provides us with the ability to interact with files that are in CSV format, which is nothing but a text file format. That is, the data stored inside the CSV files is human-readable.
The csv module requires that the file is opened before the methods supplied by the csv module can be applied. Let's take a look at how we can start with the very basic operation of reading data from CSV files.
Reading data from CSV files is quite easy and consists of the following steps:
csv_file = open('path to csv file')Here, we are reading the file using the Python open() method and then passing it the name of the file from which the data is to be read.
file object using the csv module's reader method:import csv csv_data = csv.reader(csv_file)
In the first line, we imported the csv module, which contains the...