Skip to content

Instantly share code, notes, and snippets.

@deanlxvii
Created October 14, 2011 12:43
Show Gist options
  • Save deanlxvii/1286999 to your computer and use it in GitHub Desktop.
Save deanlxvii/1286999 to your computer and use it in GitHub Desktop.
replace string in file
import os
def replace(fileName, sstr, rstr):
"""
replace sstr for rstr in a file
"""
input = open(fileName, 'r')
output = open('tmp.txt', 'w')
output.write(input.read().replace(sstr, rstr))
input.close()
output.close()
os.remove(fileName)
os.rename('tmp.txt', fileName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment