Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arrayOne = ["old string one", "new string one"]
- arrayTwo = ["old string two", "new string two"]
- # Variable 'path' collected from command line input
- f = open(path, "r", encoding="utf8")
- newFile = open(path.replace(".xml", "-new.xml"), "w", encoding="utf8")
- def replace(a,b):
- for data in f:
- for datatype in (arrayOne, arrayTwo):
- data = data.replace(datatype[a], datatype[b])
- newFile.write(data)
- newFile.close()
- replace(0,1)
- f.close()
- myDictionary = {'old string one' : 'new string one',
- 'old string two' : 'new string two'}
- # Variable 'path' collected from command line input
- f = open(path, "r", encoding="utf8")
- newFile = open(path.replace(".xml", "-new.xml"), "w", encoding="utf8")
- counter = 0
- for data in f:
- for key in myDictionary:
- if key in data:
- data = data.replace(key, myDictionary[key])
- counter += 1
- newFile.write(data)
- newFile.close()
- f.close()
- print 'Replaced', path, 'Made', counter, 'replacements.'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement