On this page
difflib.Differ
Prev: difflib.diff_bytes | Up: difflib | Next: difflib.get_close_matches
Rel: difflib.context_diff, difflib.diff_bytes, difflib.get_close_matches, difflib.HtmlDiff
Ref: docs.python.org — difflib.Differ
Tags: #public #python3 #stdlib #difflib
Import
import difflib
from difflib import Differ
Signature & Overview
difflib.Differ(linejunk=None, charjunk=None)
Differ is a class for comparing sequences of lines of text, and producing human-readable differences or deltas. Differ uses SequenceMatcher both to compare sequences of lines, and to compare
Methods & Attributes
Differ.compare(self, a, b)— Compare two sequences of lines; generate the resulting delta.
Usage
import difflib
diff = list(difflib.Differ().compare(["a\n", "b\n"], ["a\n", "c\n"]))
assert "- b\n" in diff and "+ c\n" in diff
Gotchas
- Produces human-readable line + intraline
?markers: For standard patch files, preferunified_diff().
REPL Inspect
from difflib import Differ
help(Differ)
Linked from
- tuts/python3/stdlib_module/difflib
- tuts/python3/stdlib_module/difflib/context_diff
- tuts/python3/stdlib_module/difflib/diff_bytes
- tuts/python3/stdlib_module/difflib/get_close_matches
- tuts/python3/stdlib_module/difflib/HtmlDiff
- tuts/python3/stdlib_module/difflib/Match
- tuts/python3/stdlib_module/difflib/ndiff
- tuts/python3/stdlib_module/difflib/restore
- tuts/python3/stdlib_module/difflib/SequenceMatcher
- tuts/python3/stdlib_module/difflib/unified_diff
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/get_close_matches Linked here; links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/HtmlDiff 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/Match links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/ndiff links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/restore links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/SequenceMatcher links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/unified_diff links to this page; shared tags: #difflib, #stdlib