Advertisement
pleabargain

python 3 the hard way lesson 17

May 3rd, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. #http://learnpythonthehardway.org/book/ex17.html
  2. #
  3. #takes to file names
  4. #one file in and one file out
  5. #eg
  6. #C:\Python33>python PTHW17.py 1.txt.txt 2.txt
  7.  
  8. from sys import argv
  9. from os.path import exists
  10.  
  11. script, from_file, to_file =argv
  12.  
  13. print ("Copying from {} to {}".format(from_file, to_file))
  14.  
  15. #we could do this on one line but I don't know how yet
  16.  
  17. in_file = open(from_file)
  18. indata = in_file.read()
  19.  
  20. print ("The input file is {} long".format(len(indata)))
  21.  
  22. print ("Does the output file exist? {}".format(exists(to_file)))
  23.  
  24. print ("Ready? hit RETURN to continue. ctrl - c to abort")
  25. input()
  26.  
  27. out_file = open(to_file,'w')
  28. out_file.write(indata)
  29.  
  30. print ("Alright, all done.")# File {} is copied to File {}".format(from_file,out_file)))
  31.  
  32. out_file.close()
  33. in_file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement