Python Error io.UnsupportedOperation: not readable

i have this error and i don’t know why i got it. I followed the steps from my Python manual and i got this. I am tryng to cleanup the file on column 8 and 9 if they have that odd character. If someone could help me, please advise.

The error appear on the line of code: for row in csv.reader(f):

Please find below my code:

    import csv


file = '/Users/cohen/Desktop/sdn-2.csv'
newstring = "null"
newinteger = int(0)
with open(file, 'r+') as f:
    for row in csv.reader(f):
       if row[7] =="-0-":
           row[7] = newinteger
       if row[8] == "-0-":
           row[8] = newinteger
f.close()

***LATER EDIT I changed the code as above, but is not doing anything is not replacing the -0- with 0

Leave a Comment