#!/usr/bin/env python
# -*- coding:utf-8 -*-
import time
a = time.time()
print("开始检测,请耐心等待,文件较大需要时间越长,完毕本界面会跳出提示")
def file_qc():
str1 = []
file_1 = open("d:/1.txt","r",encoding="utf-8")
for line in file_1.readlines():
str1.append(line.replace("\n",""))
str2 = []
file_2 = open("d:/2.txt", "r", encoding="utf-8")
for line in file_2.readlines():
str2.append(line.replace("\n", ""))
str_dump = []
for line in str1:
if line in str2:
str_dump.append(line) #将两个文件重复的内容取出来
str_all = set(str1 + str2) #将两个文件放到集合里,过滤掉重复内容
for i in str_dump:
if i in str_all:
str_all.remove(i) #去掉重复的文件
print("正在写去重后的结果,请稍等")
for str in str_all: #去重后的结果写入文件
with open("d:/去重后.txt","a+",encoding="utf-8") as f:
f.write(str + "\n")
if __name__=="__main__":
file_qc()
print('耗时(秒):%f' % (time.time() - a))
print("30秒后自动关闭该界面,你也可以现在手动关闭")
time.sleep(30)