我想从两个文件发现差别,但我依然从两个文件寻找差异不工作
得到答案这是我的代码
#File one(This file contents should be removed after comparing file two)
a = open('diff1','r+')
#File two
#This file has 999999 records
b = open('gtin','r+')
f8 = open('missing-test-remove.txt','w')
def diff(a, b):
c = set(a).union(set(b))
d = set(a).intersection(set(b))
result = list(c - d)
for s in result:
print s
f8.write(s)
diff(a,b)
但我依然从两个文件获得相同的结果,但文件内容,一个均应使用文件比较两个
请在处理文件时使用上下文管理。 ''open'('diff1')as:'... –
你只是想在比较两个文件并删除从'File one'重复的元素之后再写一个新列表? –
您可能会发现使用标准库中的'filecmp'更简单https://docs.python.org/2/library/filecmp.html – cdarke