from sys import argv
from os.path import exists
script, from_file, to_file = argv
print "Copying from %s to %s" % (from_file, to_file)
input = open(from_file)
indata = input.read()
print "The input file is %d bytes long" % len(indata)
print "Does the output file exist? %r" % exists(to_file)
print "Ready, hit RETURN to continue, CTRL-C to abort."
raw_input()
output = open(to_file, 'w')
output.write(indata)
print "Alright, all done."
output.close()
input.close()
Why do you have to do output.close() in the code. Why input.close() also?
If you comment the last 2 lines code works perfect, no error given, so I really don’t understand why you have to do it.
although files are closed when a program exits (which is why it still worked when you commented out those lines), it’s good practice to close files that you are finished with. as if this was a function and was called by some other function and you didn’t close the files, it would leak file descriptors and after awhile the program would run out of them.