码迷,mamicode.com
首页 > 其他好文 > 详细

ex17.py

时间:2016-11-19 03:37:09      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:close   ret   pat   exist   count   odi   imp   port   os.path   

 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()

 

ex17.py

标签:close   ret   pat   exist   count   odi   imp   port   os.path   

原文地址:http://www.cnblogs.com/jiangzhipeng/p/6079687.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!