-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff_checker.py
More file actions
46 lines (30 loc) · 1.22 KB
/
Copy pathdiff_checker.py
File metadata and controls
46 lines (30 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sys, difflib
def print_diff(ans_key, built_ans):
# ans_key is longer than built_ans
# with open(ans_key) as file_1:
# file_1_text = file_1.readlines()
# with open(built_ans) as file_2:
# file_2_text = file_2.readlines()
# results = []
# # Find and print the diff:
# for line in difflib.unified_diff(
# file_1_text, file_2_text, fromfile=ans_key,
# tofile=built_ans, lineterm=''):
# print(line)
# results.append(line)
with open(ans_key) as file_1, open(built_ans) as file_2:
differ = difflib.Differ()
for line in differ.compare(file_1.readlines(), file_2.readlines()):
print(line)
# with open('diffs.txt', 'w', encoding='utf-8') as file_0: # output_file = open('test_output.pos', 'a', encoding='utf-8')
# for res in results:
# file_0.write(res)
# file_0.close()
file_1.close()
file_2.close()
if __name__ == '__main__':
#print('enter: python3 diff_checker.py WSJ_24.pos test_output.pos')
ans_key = sys.argv[1] # f1: WSJ_24.pos, etc.
built_ans= sys.argv[2] # f2: our program-generated results
print_diff(ans_key, built_ans)
print("done")