Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import fileinput
- def replace_text_in_file_demo():
- """
- 1. The original file is moved to a backup file
- 2. The standard output is redirected to the original file within the loop
- 3. Thus any print statements write back into the original file
- """
- for line in fileinput.input('foo.txt', inplace=True, backup='.bak'):
- print line.replace("foo", "bar"),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement