1
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()
爲什麼你必須在代碼中做output.close()。爲什麼input.close()也是? 如果你對此有何評論最後兩行代碼可以完美運行,沒有錯誤給出,所以我真的不明白,爲什麼你必須這樣做。LPTHW練習17,額外學分6