Reading CSV files with reader objects

This recipe will show you how to read CSV files, specifically how to create and use the reader object.

Getting ready

To step through this recipe, you will need to install Python v2.7. To work with the CSV files, we have a nice module, csv, which is packaged with the default Python installation. So, let's get started!

How to do it...

  1. On your Linux/Mac computer, go to Terminal and use Vim, or choose your favorite editor.
  2. We start by creating a CSV file. As we know, a CSV file has a structured format where data is separated by commas, so creating one should be trivial. The following screenshot is of a CSV file that contains details of contacts in different parts of the country. We name it as mylist.csv:

  3. Now, let's ...

Get Automate it! - Recipes to upskill your business now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.