Python:读取两个文件,并将其生成为新文件
发布时间
阅读量:
阅读量
with open(r'result.txt',"w",encoding="UTF-8") as fp:
with open(r"C:\ Users\ 苟辉朋\ Desktop\ file1.txt","r+",encoding="UTF-8") as f1, open(r'C:\ Users\ 苟辉朋\Desktop\ file2.txt',"r+",encoding="UTF-8") as f2:
while True:
line1 = f1.readline()
line2 = f2.readline()
if line1 or line2:
if line1:
fp.write(line1)
if line2:
fp.write(line2)
else:
break
#打印结果
with open(r'result.txt',encoding="UTF-8") as fp:
print(fp.read())
全部评论 (0)
还没有任何评论哟~
