finding out the number of rows in a CSV file [Resolved]

Peter Otten __peter__ at web.de
Wed Aug 27 09:50:06 EDT 2008


Jon Clements wrote:

> On Aug 27, 12:54 pm, SimonPalmer <simon.pal... at gmail.com> wrote:

>> after reading the file throughthe csv.reader for the length I cannot
>> iterate over the rows.  How do I reset the row iterator?
> 
> If you're sure that the number of rows is always less than 200.

Or 2000. Or 20000...

Actually any number that doesn't make your machine fall into a coma will do.

> Slightly modify Simon Brunning's example and do:
> 
> rows = list( csv.reader(open('filename.csv')) )
> row_count = len(rows)
> for row in rows:
>     # do something

Peter



More information about the Python-list mailing list