Differences between revisions 2 and 4 (spanning 2 versions)
Revision 2 as of 2023-03-01 16:13:41
Size: 822
Comment:
Revision 4 as of 2023-04-22 21:13:04
Size: 906
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:

'''`difflib`''' is a module for producing file diffs.
Line 9: Line 11:
== HtmlDiff == == Usage ==

=
== HtmlDiff ===
Line 28: Line 32:
== Context_Diff == === Context_Diff ===
Line 34: Line 38:
== Get_Close_Matches == === Get_Close_Matches ===
Line 40: Line 44:
== NDiff == === NDiff ===
Line 46: Line 50:
== Restore == === Restore ===
Line 52: Line 56:
== Unified_Diff == === Unified_Diff ===

Python DiffLib

difflib is a module for producing file diffs.


Usage

HtmlDiff

from pathlib import Path
import difflib

old = Path('v1.txt')
new = Path('v2.txt')
out = Path('diff.html')

d = difflib.HtmlDiff(wrapcolumn=80).make_file(old, new, fromdesc='v1.txt', todesc='v2.txt')
with open(out, "w") as f:
    f.write(d)


Context_Diff


Get_Close_Matches


NDiff


Restore


Unified_Diff

from pathlib import Path
import difflib

old = Path('v1.txt')
new = Path('v2.txt')
d = difflib.unified_diff(old, new, fromfile='v1.txt', tofile='v2.txt')


See also

Python difflib module documentation


CategoryRicottone

Python/DiffLib (last edited 2023-10-11 17:02:52 by DominicRicottone)