Advertisement
Guest User

Untitled

a guest
May 4th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #!/usr/bin/python
  2. import sys
  3. import os
  4. import string
  5.  
  6. if(len(sys.argv) < 2):
  7. print ("Adj meg egy file-t!")
  8. exit()
  9.  
  10. if (not os.path.isfile(sys.argv[1])):
  11. print ("Nincs ilyen file!")
  12. exit()
  13.  
  14. a=list()
  15. b=list()
  16. fajlnev = sys.argv[1]
  17. with open(fajl) as lines:
  18. for line in lines.readlines():
  19. aktual = line.split(' ')
  20. if aktual[0]=="#::":
  21. a.append(aktual[1])
  22. if aktual[0]=="#::":
  23. b.append(aktual[2][:-1])
  24.  
  25. dictionary = dict(zip(a, b))
  26.  
  27. filename = sys.argv[1].split(".")
  28. outfile=filename[0]+"_out.py"
  29.  
  30. def switch(text, dic):
  31. for i, j in dic.iteritems():
  32. text = text.replace(i, j)
  33. return text
  34.  
  35. kiiras = open(outfile,'w')
  36. with open(fajlnev) as lines:
  37. for line in lines.readlines()[len(a):]:
  38. kiiras.write(switch(line, dictionary))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement