《笨办法学python》习题17:更多文件操作
2018-03-21 22:32
274 查看
from sys import argv from os.path import exists #我们 import 了又一个很好用的命令 exists。这个命令将文件名字符串作为参数,如果文件存在的话,它将返回 True,否则将返回 False。 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." raw_input() output = open(to_file, 'w') #将from_file的内容复制到to_file output.write(indata) print "Alright, all done." output.close() input.close()
相关文章推荐
- 笨方法学习Python-习题17: 更多文件操作
- 笨方法学Python 习题 17: 更多文件操作
- 习题17 更多文件操作
- Exercise 17:更多文件操作
- Learn Python The Hard Way学习(17) - 更多的文件操作
- 笨办法学python17 更多文件操作
- 练习17——更多文件操作
- C语言习题5.24--文件操作1
- C语言习题5.26--文件操作3
- 《笨办法学python》习题16:读写文件
- 17、Python中的文件操作
- oj Problem A: C语言习题5.24--文件操作1
- Problem D: C语言习题5.25--文件操作2
- Problem D: C语言习题5.25--文件操作2
- 1.文件io操作习题
- C语言习题5.26--文件操作3
- python17 更多文件相关
- oj Problem B: C语言习题5.25--文件操作2
- *Delphi中ExtractFilePath、ParamStr以及更多文件/目录操作涉及的函数。附加对应的例子
- YTU 2972: C语言习题5.24--文件操作1