I am trying to read and write on the same CSV file:
file1 = open(file.csv, \'rb\') file2 = open(file.csv, \'wb\') read
If your csv file is not big enough(to explode the memory), read it all into memory and close the file before open it in write mode.
Or you should consider writing to a new file rather than the same one.