Incomplete file read, or something else?

Hi JB Community,
I'm trying to create a sorting program that deals with csv files and the python csv library. I'm using a lot of nested for loops and if statements and it looks something like this:

data = csv.writer(open(writepath), dialect='excel')
for thing1 in set1          # Conditions to be compared
   for thing2 in set2       # by the 'if' statements
      for thing3 in set3    # in the following code
         derp = csv.reader(open(readpath), 'U')  #Problem here
         <initialization stuff>
         i = 0
         for herp in derp
            if ...:
if ...:
   if ...:
      do stuff
      i +=1
         data.writerow([stuff])

The .csv file read in has 7 columns in it and is created earlier in the same script from a similar looking for-if structure. It will go through like 600 of the 700 rows in the .csv file and then stops on the 601st row, 2-characters in to the fifth cell

I printed out each row as the for loop iterated and it looked like this:
...
[cell1, cell2, cell3, cell4, cell5, cell6, cell7]
[cell1, cell2, cell3, cell4, cell5, cell6, cell7]
[cell1, cell2, cell3, cell4, cell5, cell6, cell7]
[cell1, cell2, cell3, cell4, cell5, cell6, cell7]
[cell1, cell2, cell3, cell4, cell5, cell6, cell7]
[cell1, cell2, cell3, cell4, ce]

At which point my program informs me that I am referencing an index outside the bounds of the list.. but all the other rows worked fine. It's just that it stops there for some reason. I have no idea why. Shouldn't csv.reader read in the whole file? Does anyone know of any bugs associated with this library that would explain this problem?

Thanks,
Danny
-1

Please sign in to leave a comment.