Created
December 18, 2015 09:14
-
-
Save minikomi/661867533d24b8d82429 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import glob | |
from tempfile import mkstemp | |
from shutil import move | |
from os import remove, close | |
import re | |
def replace(file_path, pattern, subst): | |
fh, abs_path = mkstemp() | |
with open(abs_path, 'w') as new_file: | |
with open(file_path) as old_file: | |
new_file.write(re.sub(pattern, subst, old_file.read())) | |
close(fh) | |
remove(file_path) | |
move(abs_path, file_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment