finding out the number of rows in a CSV file

Jon Clements joncle at
Wed Aug 27 13:29:13 CEST 2008

On Aug 27, 12:16 pm, SimonPalmer <simon.pal... at> wrote:
> anyone know how I would find out how many rows are in a csv file?
> I can't find a method which does this on csv.reader.
> Thanks in advance

You have to iterate each row and count them -- there's no other way
without supporting information (since each row length is naturally
variable, you can't even use the file size as an indicator).

Something like:

row_count = sum(1 for row in csv.reader( open('filename.csv') ) )


More information about the Python-list mailing list