This feels like a stupid mistake, but I am unable to spot it. When I execute this code:
with open('test.csv') as csvfile:
# row_count = sum(1 for row in csvfile)
reader = csv.DictReader(csvfile, delimiter = ';')
path = os.getcwd() # ← gets current directory
for row in reader:
header = row['FirstName'] + ' ' + row['Surname'] + ' – #' + row['RecruitmentID'].zfill(5)
print('Processing: ' + ' / ' + header)
what I get is:
Processing: / AAA aaa – #00005
Processing: / BBB bbb – #00008
Processing: / CCC ccc – #00160
[Finished in 0.3s]
But when I uncomment # row_count = sum(1 for row in csvfile) I only get [Finished in 0.3s] in the console.
Even using another method: numberofrows = len(list(reader)) instead breaks it the same way. What am I doing wrong?
row_count = sum(1 for row in csvfile)you go to the end of your file , this way the csv reader won't fine anything else, try doingcsvfile.seek(0), that should take you back at the beginning of the file, before creating the csv readerpypdftkorpath = os.getcwd()makes other users read too much code (and think about it) that has nothing to do with your question. Thank you.