[Tutor] Processing rows from CSV

Kent Johnson kent37 at tds.net
Tue Nov 17 21:50:49 CET 2009

On Tue, Nov 17, 2009 at 1:57 PM,  <mhw at doctors.net.uk> wrote:

> A rather general question, I'm afraid. I have found myself writing some python code to handle some CSV data, using the csv. DictReader that generates a dict for each row with the key as the column heading and the value in the file as the item. Most operations involve code of the form: (Apologies for incorrect caps)
> For row in reader:
>    If row['foo'] == 'something' :
>        do this etc.

> My other question was about how I do this more efficiently: I don't want to read the whole thing into memory at once, but (AFAIK) csv.DictReader doesn't support something like readline() to deliver it one at a time.

The loop above does deliver one line worth of data at a time.


More information about the Tutor mailing list