Python 比较两个文件的重复项,并将结果发送到第三个文件
必须检查2个文件:Python 比较两个文件的重复项,并将结果发送到第三个文件,python,duplicates,Python,Duplicates,必须检查2个文件: 文件archive.txt包括已存档的用户名 文件import.txt包括必须使用archive.txt检查的用户名 如果导入的用户名未包含在archive.txt中,则应将其保存到第三个输出文件(new.txt) 我发现了一些有趣的代码片段,但它只比较并将新条目直接写入文件。我无法将其写入第三个文件 有什么想法吗 以open('./export/import.txt',r')作为填充,以open('./process/new.txt',w')作为输出文件: seen=set
以open('./export/import.txt',r')作为填充,以open('./process/new.txt',w')作为输出文件:
seen=set()
对于填充中的线:
对于第行中的单词。拆分():
如果看不到单词:
见。添加(word)
outfile.write('{}\n'.格式(word))
这应该会有所帮助
with open('./export/archive.txt', 'r') as archive, open('./export/import.txt', 'r') as importtxt, open('./export/new.txt', 'w') as outfile:
toCheck = archive.read()
for word in importtxt:
if word not in toCheck:
outfile.write('{}\n'.format(word))
这应该会有所帮助
with open('./export/archive.txt', 'r') as archive, open('./export/import.txt', 'r') as importtxt, open('./export/new.txt', 'w') as outfile:
toCheck = archive.read()
for word in importtxt:
if word not in toCheck:
outfile.write('{}\n'.format(word))
这应该会有所帮助