finding the diff

Peter Otten __peter__ at web.de
Fri Sep 11 09:03:06 CEST 2015


Noah wrote:

> I am researching a nice slick way to provide the difference between
> generated python multi-line configuration output and specific
> configuration lines gathered from an output file.  I could put things in
> a list?   I could put both forms output into IOString() and run a diff
> command to it?

There's difflib in Python's standard library:

>>> import difflib
>>> print("".join(difflib.unified_diff(
... ["foo\n", "bar\n", "baz\n"],
... ["foo\n", "baz\n", "bang\n"])))
--- 
+++ 
@@ -1,3 +1,3 @@
 foo
-bar
 baz
+bang




More information about the Python-list mailing list