Python Error io.UnsupportedOperation: not readable

Python Error io.UnsupportedOperation: not readable


You need to open the file with r+. Using w is for write only, r+ is for both write and read access.

with open(file, r+) as f:

Using == as in row[7] == newinteger is calling the equality operator. It checks if the left and right operands values are the same. You want to be setting the new value with =.

row[7] = newinteger

The other stuff that those before me said too but I think this error is from the parentheses around the string -0-. And maybe the space on the first use as well.

if row[7] ==(-0-):

should be:
if row[7] == -0-:

if row[8] == (-0-):

should be:
if row[8] == -0-:

Python Error io.UnsupportedOperation: not readable

This was my solution: to create an output file and to write in it, what i read from the source file. Is a bit odd, as in VBA was even easier to do this, then in python, but this is the solution within the csv module from pythn. I dont like that i have to create another file, and i cant basicaly write inside the readed file, and i have to write into a brand new file, but this is life….If someone has a better approach, I am opened to new.

Hope that others will use this code.

import csv
newstring = null
newinteger = (0)
with open(/Users/cohen/Desktop/sdn-4 2.csv, r) as file1, open(/Users/cohen/Desktop/new_sdn.csv, w, newline=) as file2:
    reader = csv.reader(file1, delimiter=,)
    writer = csv.writer(file2, delimiter=,)

    for row in reader:
        replaced1 = row[7].replace(-0-, newstring)
        replaced2 = row[8].replace(-0-, newinteger)

Leave a Reply

Your email address will not be published. Required fields are marked *