Skip to content

Instantly share code, notes, and snippets.

@osya
Last active February 17, 2018 10:26
Show Gist options
  • Save osya/752f682de132bf4dd24105486e579aaa to your computer and use it in GitHub Desktop.
Save osya/752f682de132bf4dd24105486e579aaa to your computer and use it in GitHub Desktop.
Search & Replace in files #Python
import glob
replace = 'https://github.com/osya'
replacement = '[email protected]:osya'
for filename in glob.iglob('E:/Work/**/.git/config', recursive=True):
with open(filename) as f:
s = f.read()
if replace in s:
print(filename)
s = s.replace(replace, replacement)
with open(filename, "w") as f:
f.write(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment