Created
December 2, 2019 18:51
-
-
Save anmolj7/2ef77630c43ae80cce87f3150e1e8642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Write a Python script to search for text in a file and replace it, for example, there is a text file that reads Hello World, change it to Hello name. The intended output is the link to the gist. | |
''' | |
fName = input("Enter the file's name: ") | |
with open(fName) as f: | |
data = f.read() | |
repl = input("Enter the text to be replaced: ") | |
word = input(f"Replace {repl} to: ") | |
data = data.replace(repl, word) | |
with open(fName, "w+") as file: | |
file.write(data) | |
print("Done...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment