On this page
difflib.ndiff
Prev: difflib.Match | Up: difflib | Next: difflib.restore
Rel: difflib.context_diff, difflib.diff_bytes, difflib.Differ, difflib.get_close_matches
Ref: docs.python.org — difflib.ndiff
Tags: #public #python3 #stdlib #difflib
Import
import difflib
from difflib import ndiff
Signature & Overview
difflib.ndiff(a, b, linejunk=None, charjunk=<function IS_CHARACTER_JUNK at 0x109cd6140>)
Compare a and b (lists of strings); return a Differ-style delta.
Usage
import difflib
diff = list(difflib.ndiff(["one\n", "two\n"], ["one\n", "too\n"]))
assert "- two\n" in diff and "+ too\n" in diff
Gotchas
- Convenience wrapper around
Differ().compare(): Pair withdifflib.restore(diff, 1)orrestore(diff, 2)to reconstruct either side.
REPL Inspect
from difflib import ndiff
help(ndiff)
Linked from
Related notes
- tuts/python3/stdlib_module/difflib/Match Linked here; links to this page; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/restore 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/context_diff Linked here; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/diff_bytes Linked here; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/Differ Linked here; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/get_close_matches Linked here; shared tags: #difflib, #stdlib
- tuts/python3/stdlib_module/difflib/HtmlDiff 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