Python-Day4 achieves simple shell sed replacement function, python-day4sed
Code:
1 f = open ('yesterday', 'R', encoding = 'utf-8') 2 f2 = open ('Yesterday. bak ', 'w', encoding = 'utf-8') 3 old_str = input ('Enter the character to modify :') 4 replace_str = input ('Enter the character to replace with: ') 5 for line in f. readlines (): 6 line = line. replace (old_str, replace_str) 7 print (line) 8 f2.write (line) 9 f. close () 10 f2.close ()
File Content: (yesterday)
Somehow, it seems the love I knew was always the most destructive kind Somehow, the love I 've experienced is always The most devastating Yesterday when I was young and frivolous The taste of life was sweet The taste of life is sweet As rain upon my tongue is like a tongue rain on
Thoughts:
The idea is very simple: Open the source file, and then loop, replace the content to be replaced by the source file and write it into the new file!