获取两个txt文件有差异的内容
def get_txt_diff(txt_path_1, txt_path_2, txt_path):
f = open(txt_path_1, 'r', encoding='utf-8')
ff = open(txt_path_2, 'r', encoding='utf-8')
fff = open(txt_path, 'w', encoding='utf-8')
with f, ff:
content_1_list = f.readlines()
content_2_list = ff.readlines()
# txt_path_1-txt_path_2
content_diff_list = list(set(content_1_list).difference(set(content_2_list)))
for content in content_diff_list:
fff.write(content)
if __name__ == '__main__':
txt_path_1 = "test_1.txt"
txt_path_2 = "test_2.txt"
txt_path = "test.txt"
get_txt_diff(txt_path_1, txt_path_2, txt_path)
标签:__,差异,list,content,获取,diff,path,txt
From: https://blog.csdn.net/familytaijun/article/details/140926902