I am probably making a stupid mistake, but I can't find where it is. I want to count the number of lines in my csv file. I wrote this, and obviously isn't working: I have row_count = 0
while it should be 400. Cheers.
f = open(adresse,"r")
reader = csv.reader(f,delimiter = ",")
data = [l for l in reader]
row_count = sum(1 for row in reader)
print row_count
First you have to open the file with open
Then use the csv.reader for open the csv
At the last, you can take the number of row with the instruction 'len'
The total code is this:
Remember that if you want to reuse the csv file, you have to make a input_file.fseek(0), because when you use a list for the reader_file, it reads all file, and the pointer in the file change its position
You are trying to read the file twice, when the file pointer has already reached the end of file after saving the
data
list.