csv.reader length?

7stud bbxx789_05ss at yahoo.com
Fri May 25 15:49:43 EDT 2007


On May 25, 12:49 pm, cjl <cjl... at gmail.com> wrote:
> P:
>
> Stupid question:
>
> reader = csv.reader(open('somefile.csv'))
> for row in reader:
>     do something
>
> Any way to determine the "length" of the reader (the number of rows)
> before iterating through the rows?
>
> -CJL

How about:

f = open("somefile.csv")
numlines = len(f.readlines())




More information about the Python-list mailing list