I am currently working on a project that uses the csv module in python. I have created a separate class to open a pre-existing csv file, modify the data on each line, then save the data to a new csv file.
The original file has 1438 rows, and by placing some test code into the class that handles the writing, it indicates that it is writing 1438 rows to the new csv file. Upon inspection of the file itself, there is infact 1438 rows in the newly created file. However, when I use the standard cvs module in this way:
reader = csv.reader(open('naiveData.csv', 'rb'))
It only goes to row 1410 (and not even then entire row, it ends one and a half indices before the end of the row. I am not sure what may be causing this.
This is how I am accessing the reader:
for row in reader:
print row
Here is the part of the output where it fails:
['UNPM', '16', '2.125', '910', 'athlete', 'enrolled']
['UNPM', '14', '2.357', '1020', 'non-athlete', 'enrolled']
['UNDC', '17', '2.071', '910', 'athlete', 'unenrolled']
['KINS', '15', '2.6', '910', 'athlete', 'enrolled']
['PHYS', '16', '1.5', '900', 'non-']
The last list should have ['PHYS', '16', '1.5', '900', 'non-athlete', 'enrolled'].
Any ideas as to what may be causing this? Thanks in advance!
Edit:
Here are the lines in the CVS file around the area the error is occuring:
KINS,15,2.6,910,athlete,enrolled
PHYS,16,1.5,900,non-athlete,enrolled
UNPL,15,3,960,non-athlete,enrolled
.close()or are you using awithstatement to make sure the file is properly closed? I'm wondering if the file is not being fully written somehow before your writing program terminates. If you are using CPython this doesn't seem likely, but if you are using Jython or PyPy it seems possible.