将一个文件的内容复制到另一个文件
with open(input_file, 'r') as in_file, open(output_file, 'w') as out_file:
for line in in_file:
out_file.write(line)
- 使用
shutil
模块:
import shutil
shutil.copyfile(src, dst)
with open(input_file, 'r') as in_file, open(output_file, 'w') as out_file:
for line in in_file:
out_file.write(line)
shutil
模块:import shutil
shutil.copyfile(src, dst)