写规范点呗,就这样
[Python] 纯文本查看 复制代码 #!/usr/bin/env python
# -*- coding:utf-8 -*-
import time
def ReadFile(file_path):
with open(file_path, 'r', encoding='utf-8') as file_object:
return [lines.replace('\n', '') for lines in file_object.readlines()]
def SaveFile(file_path, str_list):
with open(file_path, "a+", encoding='utf-8') as file_object:
file_object.writelines([_str+'\n' for _str in str_list])
def TextDeDuplication(file_path_1, file_path_2, save_path):
SaveFile(save_path, set(ReadFile(file_path_1) + ReadFile(file_path_2)))
if __name__ == "__main__":
start_time = time.time()
print('开始检测,请耐心等待,文件较大需要时间越长,完毕本界面会跳出提示')
print('正在写去重后的结果,请稍等')
TextDeDuplication('1.txt', '2.txt', '3.txt')
print(f'耗时(秒):{time.time() - start_time}')
print('10秒后自动关闭该界面,你也可以现在手动关闭')
time.sleep(10)
|