Created
April 28, 2013 21:02
-
-
Save xexu/5478411 to your computer and use it in GitHub Desktop.
replace utility for large files
This file contains 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
# -*- coding: utf-8 -*- | |
import os, codecs, sys | |
dir = os.getcwd() | |
file = sys.argv[1] | |
Dict = [['a', 'b'], ['c', 'd']] | |
fname = os.path.join(dir, file) | |
inFile = codecs.open(fname, "r", "utf-8") | |
outFile = codecs.open(fname + ".new", "w", "utf-8") | |
for line in inFile: | |
for Dictrow in Dict: | |
line = line.replace(Dictrow[0], Dictrow[1]) | |
outFile.write(line) | |
print line | |
inFile.close() | |
outFile.close() | |
os.rename(fname + ".new", fname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment