Python学习10-拷贝文件

上一篇 / 下一篇  2014-06-25 16:04:03 / 个人分类:笨办法学Python

$ex17.py 源码
from sys import argv
from os.path import exists #从os.path模组中导入exists方法

script, from_file, to_file = argv

print ("Copying from %s to %s" % (from_file, to_file))

inputfile = open(from_file)
indata = inputfile.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.")
input()

output = open(to_file, 'w')
output.write(indata)

print ("Alright, all done.")

output.close()
inputfile.close()

len()获取文件大小
exists()判断文件是否存在


TAG:

 

评分:0

我来说两句

Open Toolbar