Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. arrayOne = ["old string one", "new string one"]
  2. arrayTwo = ["old string two", "new string two"]
  3.  
  4. # Variable 'path' collected from command line input
  5. f = open(path, "r", encoding="utf8")
  6. newFile = open(path.replace(".xml", "-new.xml"), "w", encoding="utf8")
  7.  
  8. def replace(a,b):
  9. for data in f:
  10. for datatype in (arrayOne, arrayTwo):
  11. data = data.replace(datatype[a], datatype[b])
  12. newFile.write(data)
  13. newFile.close()
  14.  
  15. replace(0,1)
  16.  
  17. f.close()
  18.  
  19. myDictionary = {'old string one' : 'new string one',
  20. 'old string two' : 'new string two'}
  21.  
  22. # Variable 'path' collected from command line input
  23. f = open(path, "r", encoding="utf8")
  24. newFile = open(path.replace(".xml", "-new.xml"), "w", encoding="utf8")
  25. counter = 0
  26.  
  27. for data in f:
  28. for key in myDictionary:
  29. if key in data:
  30. data = data.replace(key, myDictionary[key])
  31. counter += 1
  32. newFile.write(data)
  33. newFile.close()
  34.  
  35. f.close()
  36.  
  37. print 'Replaced', path, 'Made', counter, 'replacements.'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement