Code
1f = open ('Yesterday','R', encoding='Utf-8')2F2 = open ('Yesterday.bak','W', encoding='Utf-8')3OLD_STR = input ('Please enter the characters you want to modify:')4REPLACE_STR = input ('Please enter a replacement character:')5 forLineinchf.readlines ():6line =line.replace (OLD_STR,REPLACE_STR)7 Print(line)8 F2.write (line)9 f.close ()TenF2.close ()
File contents: (Yesterday)
Somehow, it seems the love I knew is always the most destructive kind I don't know why, I went through the most devastating of the kind yesterday when I am young yesterday when I Young and frivolous The taste's life is sweet as rain upon my tongue like the dew on the tongue
Feelings:
The idea is simple is to open the source file, and then loop, the source file to replace the content to replace and then write new files!
Python-day4 implements a simple shell sed replacement function