Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import os, sys
  4.  
  5. import glob
  6.  
  7. nargs = len(sys.argv)
  8.  
  9. if not 3 <= nargs <= 5:
  10. print "usage: %s search_text replace_text [infile [outfile]]" % \
  11. os.path.basename(sys.argv[0])
  12. else:
  13. stext = sys.argv[1]
  14. rtext = sys.argv[2]
  15. input = sys.stdin
  16. output = sys.stdout
  17. files = glob.glob('./employee/*/*py')
  18. for file in files:
  19.  
  20. if nargs > 3:
  21. input = open(file)
  22. if nargs > 4:
  23. output = open(file + '_copy', 'w')
  24. for s in input.xreadlines( ):
  25. output.write(s.replace(stext, rtext))
  26. output.close( )
  27. input.close( )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement