[Tutor] line number when reading files using csv module

Duncan Gibson duncan at thermal.esa.int
Fri Oct 27 11:52:55 CEST 2006


On Fri, 27 Oct 2006 11:35:40 +0200
Duncan Gibson <duncan at thermal.esa.int> wrote:

> 
> If I have the following data file, data.csv:
>     1 2 3
>     2 3 4 5
> 
> then I can read it in Python 2.4 on linux using:
> 
>     import csv
>     f = file('data.csv', 'rb')
>     reader = csv.reader(f)
>     for data in reader:
>         print data

Oops, mixing examples here. I forgot to say that
I'm actually using

    reader = csv.reader(f, delimiter=' ')

so it will read the data correctly even if there
isn't a comma in sight in the csv file, but that's
a side issue to the line number problem.

Cheers
Duncan


More information about the Tutor mailing list