Exercise 17, extra credit 6 Learn python the hard way: Find out why you had to do output.close() in the code.
Code: 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() I don't get it. If you don't close input and output it works exactly the same as if you would close them, so why do you have to do output.close() and input.close()? Also does it matter if you do: input.close() and then output.close()? Is there an order to follow? Thanks in advance, amt. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor