I'm trying to search through a file for a line that contain certain text and then replace that entire line with a new line.
I'm trying to use:
pattern = "Hello"
file = open('C:/rtemp/output.txt','w')
for line in file:
if pattern in line:
line = "Hi\n"
file.write(line)
I get an error saying:
io.UnsupportedOperation: not readable
I'm not sure what I'm doing wrong, please can someone assist.