ex17.py

 1 # -*- coding:utf-8 -*-
 2 from sys import argv 
 3 from os.path import exists
 4 
 5 script, from_file, to_file = argv
 6 
 7 print ("copying from %s to %s" % (from_file, to_file))
 8 
 9 # we could do these two on one line too,how?
10 in_file = open(from_file)
11 indata = in_file.read()
12 
13 print("the input fule is %d bytes long" % len(indata))  #学会使用len()函数
14 
15 print ("Does the output file exist? %r" % exists(to_file))
16 print ("Ready,hit RETURN to countinue, CTRL-C to abort.")
17 input()
18 
19 out_file = open(to_file, 'w')
20 out_file.write(indata)
21 
22 print("alright, all done.")
23 out_file.close()
24 in_file.close()

 

posted @ 2016-11-19 00:50  听风呤  阅读(176)  评论(0编辑  收藏  举报