txt 按行合并python代码
import os, sys
#按行合并
file1path = 'Chinese/2.txt'
file2path = 'Chinese/test.txt'
file_1 = open(file1path,'r',encoding='utf-8')
file_2 = open(file2path,'r',encoding='utf-8')
list1 = []
for line in file_1.readlines():
ss = line.strip()
list1.append(ss)
file_1.close()
list2 = []
for line in file_2.readlines():
ss = line.strip()
list2.append(ss)
file_2.close()
file_new = open('result2.txt','w',encoding='utf-8')
for i in range(len(list1)):
sline = list1[i] + ' ' + list2[i]
file_new.write(sline+'\n')
file_new.close()