python将多个txt文件读取,并写成一个txt

import os,shutil
match_image = open("match_image.txt", "r")
match_image_sim_class = open("match_image_sim_class.txt", "r")

match_image_file = match_image.readlines()
match_image_sim_class_file = match_image_sim_class.readlines()

print(len(match_image_file),len(match_image_sim_class_file))
核对文件数目:778042 29299

match_image_list = [] # 初始化一个空列表
for match_image_file_one in match_image_file:
    match_image_list.append(match_image_file_one) #读取一个插入一个
for sim_class in match_image_sim_class_file:
    match_image_list.append(sim_class)

len(match_image_list)
807341 #数目正确

#写入一个新的txt文件中
file = open("add_sim.txt","w")

for i in match_image_list:
    file.write(i)

猜你喜欢

转载自blog.csdn.net/qq_38640439/article/details/81410380