O'Reilly logo

Automate it! - Recipes to upskill your business by Chetan Giridhar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required