我正在测试下面的python代码,以便将内容从一个txt文件导出到另一个文件,但是目的地内容会被一些不同的语言(可能是中文)复制而不正确
# - *- coding: utf- 8 - *-
from sys import argv
from os.path import exists
script,from_file,to_file = argv
print "Does the output file exist ? %r" %exists(to_file)
print "If 'YES' hit Enter to proceed or terminate by CTRL+C "
raw_input('?')
infile=open(from_file)
file1=infile.read()
outfile=open(to_file,'w')
file2=outfile.write(file1)
infile.close()
outfile.close()
答案 0 :(得分:0)
尝试使用此代码将1个文件复制到另一个文件:
with open("from_file") as f:
with open("to_file", "w") as f1:
for line in f:
f1.write(line)