我有两个文件,我在new file
获取新行时没有任何问题,但与new_file
相比,我无法在old_file
中删除已删除的行。
我得到了所有的线条。我怎样才能删除删除的行?
import difflib
old_file=open(OUTPUT).readlines()
new_file=open(TMP_FILE).readlines()
diff = difflib.unified_diff(old_file, new_file, fromfile='file1', tofile='file2', lineterm='', n=0)
lines = list(diff)[2:]
added = [line[1:] for line in lines if line[0] == '+']
removed = [line[1:] for line in lines if line[0] == '-']
added_users=[]
for line in added:
if line not in removed:
added_users.append(line)