It does work but it doesn’t replace the letters.
First I open one file, and write the content to another. And then to the second file I replace some specific letters, but it doesn’t work, An
any idea?
The code:
def copy_file():
f=open("cartas.txt","r")
g=open("copiar.txt","r+")
g.writelines(f)
f.close()
for line in g:
line = line.replace("s","ch")
g.write(line)
g.close()
copy_file()
You are trying to iterate over the lines in
gand also write the modified lines tog. And before that you actually copy the contents fromfintog.What you should be doing is iterating over the lines of
fand write them togwhile converting them directly: