Skip to content

Instantly share code, notes, and snippets.

@btgoodwin
Created May 1, 2019 11:42
Show Gist options
  • Save btgoodwin/314afa376db02d3dc9600185dd07ea17 to your computer and use it in GitHub Desktop.
Save btgoodwin/314afa376db02d3dc9600185dd07ea17 to your computer and use it in GitHub Desktop.
Python find-replace
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