difflib.unified_diff()
difflib.unified_diff() is a Python function in the Difflib Module category. Compares two sequences and produces a unified diff output (like diff -u). The syntax is difflib.unified_diff(a, b, fromfile="", tofile="", fromfiledate="", tofiledate="", n=3, lineterm="\n"). Returns: Iterator of diff lines. A typical example: diff = difflib.unified_diff(
["line1\n", "line2\n"],
["line1\n", "line3\n"],
fromfile="old.py", tofile="new.py"
)
print("".join(diff)). A close sibling is difflib.SequenceMatcher(), which flexible sequence comparison object. Finds the longest matching subsequences. A close sibling is difflib.get_close_matches(), which returns the best `n` matches for a word from a list of possibilities. A close sibling is difflib.context_diff(), which compares sequences and produces a context diff (like diff -c). A close sibling is difflib.ndiff(), which compares sequences and produces a human-readable delta (like diff). More about this category: Sequence comparison — SequenceMatcher, get_close_matches, unified_diff. For a broader walkthrough, read the Difflib Module guide. Related Difflib Module entries: difflib.SequenceMatcher(), difflib.get_close_matches(), difflib.context_diff(), difflib.ndiff(), difflib.HtmlDiff().