笨方法学python 习题17

2017-07-07  本文已影响0人  d1b0f55d8efb
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))

# we could do these two on one line too, how?

#打开第一个文件
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.")

#以写的形式打开第二个文件
output = open(to_file, 'w')
output.write(indata) #写入indata读出的内容


print ("Alright, all done.")
output.close()
input.close()
上一篇下一篇

猜你喜欢

热点阅读