I am trying to replace all instances of a given string in a text file. I am trying to read the file line by line and then use the replace function, however it is just outputting a blank file instead of the expected. What could I be doing wrong?
file = input("Enter a filename: ")
remove = input("Enter the string to be removed: ")
fopen = open(file, 'r+')
lines = []
for line in fopen:
line = line.replace(remove,"")
fopen.close()