finding out the number of rows in a CSV file
Jon Clements
joncle at googlemail.com
Wed Aug 27 07:29:13 EDT 2008
On Aug 27, 12:16 pm, SimonPalmer <simon.pal... at gmail.com> 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') ) )
hth
Jon.
More information about the Python-list
mailing list