|
Size: 906
Comment:
|
Size: 988
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 75: | Line 75: |
| [[https://pymotw.com/3/difflib/|Python Module of the Day article for difflib]] |
Python DiffLib
difflib is a module for producing file diffs.
Contents
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
Python Module of the Day article for difflib
