On this page
difflib.HtmlDiff
Prev: difflib.get_close_matches | Up: difflib | Next: difflib.Match
Rel: difflib.context_diff, difflib.diff_bytes, difflib.Differ, difflib.get_close_matches
Ref: docs.python.org โ difflib.HtmlDiff
Tags: #public #python3 #stdlib #difflib
Import
import difflib
from difflib import HtmlDiff
Signature & Overview
difflib.HtmlDiff(tabsize=8, wrapcolumn=None, linejunk=None, charjunk=<function IS_CHARACTER_JUNK at 0x109cd6140>)
For producing HTML side by side comparison with change highlights.
Methods & Attributes
HtmlDiff.make_file(self, fromlines, tolines, fromdesc='', todesc='', context=False, numlines=5, *, charset='utf-8')โ Returns HTML file of side by side comparison with change highlights Arguments: fromlines -- list of "from" linesHtmlDiff.make_table(self, fromlines, tolines, fromdesc='', todesc='', context=False, numlines=5)โ Returns HTML table of side by side comparison with change highlights Arguments: fromlines -- list of "from" lines
Usage
import difflib
html = difflib.HtmlDiff().make_table(["old line"], ["new line"])
assert "<table" in html and "old line" in html and "new line" in html
Gotchas
make_file()produces a full standalone HTML document;make_table()produces just the<table>fragment.
REPL Inspect
from difflib import HtmlDiff
help(HtmlDiff)
Linked from
Related notes
- tuts/python3/stdlib_module/difflib/context_diff Linked here; links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/diff_bytes Linked here; links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/Differ Linked here; links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/get_close_matches Linked here; links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/Match Linked here; links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/difflib/ndiff shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/restore shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/SequenceMatcher shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/unified_diff shared tags: #difflib, #stdlib