此代码会将每个文件复制到 INPUT,每次都覆盖 INPUT:
import shutil
file_list = [file1, file2, file3]
def queue():
if condition1_met:
for item in file_list:
shutil.copyfile(item, "INPUT")
else:
return queue()
如果要将文件的内容附加到 INPUT,那么这应该可以完成工作:
蟒蛇2.6版
import contextlib
file_list = [file1, file2, file3]
def queue():
if condition1_met:
for item in file_list:
with contextlib.nested(open(item,"r"), open("INPUT","a+")) as (src,dst):
dst.writelines(src.readlines())
else:
return queue()
蟒蛇2.7版
file_list = [file1, file2, file3]
def queue():
if condition1_met:
for item in file_list:
with open(item,"r"), open("INPUT","a+") as src,dst:
dst.writelines(src.readlines())
else:
return queue()