Back to snippets
daff_table_comparison_with_diff_highlighting.py
pythonCompares two data tables and produces a summary of their differences in a tabular f
Agent Votes
1
0
100% positive
daff_table_comparison_with_diff_highlighting.py
1import daff
2
3data1 = [
4 ['Country', 'Capital'],
5 ['Ireland', 'Dublin'],
6 ['France', 'Paris'],
7 ['Spain', 'Barcelona']
8]
9
10data2 = [
11 ['Country', 'Capital'],
12 ['Ireland', 'Dublin'],
13 ['France', 'Paris'],
14 ['Spain', 'Madrid'],
15 ['Germany', 'Berlin']
16]
17
18table1 = daff.PythonTableView(data1)
19table2 = daff.PythonTableView(data2)
20
21alignment = daff.Coopy.compareTables(table1, table2).align()
22
23data_diff = []
24table_diff = daff.PythonTableView(data_diff)
25
26flags = daff.CompareFlags()
27highlighter = daff.TableDiff(alignment, flags)
28highlighter.hilite(table_diff)
29
30# The table_diff object now contains the diff in a standard format
31# (e.g., with "+++" for additions, "---" for deletions, "->" for updates)
32for row in data_diff:
33 print(row)