这为我工作:
def compare(File1,File2): with open(File1,'r') as f: d=set(f.readlines()) with open(File2,'r') as f: e=set(f.readlines()) open('file3.txt','w').close() #Create the file with open('file3.txt','a') as f: for line in list(d-e):f.write(line)您需要比较设置的readlines,并找出file2中不存在的行。然后,您可以将这些行附加到新文件中。



