2021-06-24 00:38:47 +01:00
|
|
|
### Util library for general file handling
|
|
|
|
|
|
|
|
|
|
|
|
def replaceTextInFile(filepath, oldText, newText):
|
2021-06-25 21:13:36 +01:00
|
|
|
"""Replace all occurrences of some text in plaintext file with some other text.
|
|
|
|
|
|
|
|
filepath -- the path of the plaintext file\n
|
|
|
|
oldText -- the text to replace\n
|
|
|
|
newText -- the text to implement\n
|
|
|
|
"""
|
2021-06-24 00:38:47 +01:00
|
|
|
file = open(filepath, "rt")
|
|
|
|
newFile = file.read().replace(oldText, newText)
|
|
|
|
file.close()
|
|
|
|
file = open(filepath, "wt")
|
|
|
|
file.write(newFile)
|
|
|
|
file.close
|