I created a dictionary using csv.DictReader function. First time I iterate through it, trying to print out the contents of the dictionary, my code works fine. The second time I try to do it (same line of code but further down the code), I just does not want to print. Why is that and how can I fix this?
Here is a short version of the code:
import csv
import sys
filename = sys.argv[1]
f = open(filename,'r')
reader = csv.DictReader(f, fieldnames=fieldnamesY) #filednamesY is a list that I have
for person in reader:
for fn in fieldnamesY[1:]:
person[fn] = int(person[fn]) #I had to transform string values to int
print(person) # THIS PART PRINTS OUT THE ROWS FROM THE DICTIONATY
...
...#Some line of code
...
for person in reader:
print(person) # THIS PART OF CODE DOES NOT PRINT OUT THE ROWS FROM
THE DICTIONARY
Originally, I did not even have to print out the dictionary the second time. I had to iterate through the dictionary, compare the values from that dictionary to values from a certain list, and return a specific answer based on the result. But the code simply did not work so I simplified it, I noticed it seemed like the code just does not want to go through the iteration of the dictionary the second time. So I am very confused as to why this happens.