标签:笨方法学python python基础 python入门 python
这篇对应的是习题17,更多文件操作
# -*- coding: utf-8 -*-
#对文件更多操作复制A文件的内容到B文件
#from sys import argv
from os.path import exists
prompt = "> "
from_file = raw_input("please input the filename where you want to copy from: >")
#in_file = open(from_file) #打开文件,不带参数,说明默认是读的方式
#indata = in_file.read() #读文件里面的数据,用indata存放
#indata = open(from_file).read() 上面两句可以写成一句
#print "The input file is %d bytes long" %len(indata) #这句是计算出文件的大小
to_file = raw_input("Please input the tagetfilename where you want to copy to: > ")
print "Now,copy the filename…………"
#out_file = open(to_file,‘w‘) #打开文件,带‘w‘ 表明以写的方式打开
#out_file.write(indata) #把indata里面的数据,写进去
#open(to_file,‘w‘).write(indata) #上面两句,可以写成这一句
open(to_file,‘w‘).write(open(from_file).read()) #这行是7 8 13 14行的合成一行的写法
print "Alrigh,all done"
#out_file.close()
#in_file.close()笨方法学python(5)加分题,布布扣,bubuko.com
标签:笨方法学python python基础 python入门 python
原文地址:http://blog.csdn.net/indy889/article/details/24874691