Python - comparing two text files with difflib.HtmlDiff()

Python tip:

You can use HtmlDiff to generate an HTML table that shows a side by side, line by line comparison of the text with inter-line and intra-line change highlights.

An example👇

import difflib
from pathlib import Path

first_file_lines = Path('first.txt').read_text().splitlines()
second_file_lines = Path('second.txt').read_text().splitlines()

html_diff = difflib.HtmlDiff().make_file(first_file_lines, second_file_lines)