Created
May 1, 2019 11:42
-
-
Save btgoodwin/314afa376db02d3dc9600185dd07ea17 to your computer and use it in GitHub Desktop.
Python find-replace
This file contains hidden or 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
import re | |
output_file_path = 'whatever' | |
content = None | |
with open(out_file_path, 'r') as f: | |
content = f.read() | |
# Regex find, replace pairs | |
FINDREPLACE_LIST = [ | |
( re.compile(r'FIND', re.M), r'REPLACE' ) | |
] | |
for pair in FINDREPLACE_LIST: | |
tem = re.subn(pair[0], pair[1], content) | |
content = tem[0] | |
with open(out_file_path, 'w') as f: | |
f.write(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment