###
这段代码是用于读文件、写文件
###
from sys import argv
from os.path import exists
script, from_file, to_file = argv
#获取文件内容
in_file = open(from_file)
indata = in_file.read()
#将文件内容写入到目标文件
if exists(to_file) <> 0:
open(to_file,"w").write(indata)
#结束
in_file.close()
1、open(),close(),write(T),exists(file)
什么时候需要close()?
当open().read()时,会自动调close(),此时不用再次close();
当in_file= open(file)时,需要使用close()关闭文件,否则容易造成文件坏
浙公网安备 33010602011771号