Kennen Sie eine Bibliothek, die Ihnen dabei hilft?Wie wird der Vergleich von zwei mehrzeiligen Strings im Unified-Diff-Format gedruckt?
Ich würde eine Funktion schreiben, die die Unterschiede zwischen zwei mehrzeiligen Strings im Unified-Diff-Format ausgibt. So etwas Ähnliches:
def print_differences(string1, string2):
"""
Prints the comparison of string1 to string2 as unified diff format.
"""
???
Ein Anwendungsbeispiel ist die folgende:
string1="""
Usage: trash-empty [days]
Purge trashed files.
Options:
--version show program's version number and exit
-h, --help show this help message and exit
"""
string2="""
Usage: trash-empty [days]
Empty the trash can.
Options:
--version show program's version number and exit
-h, --help show this help message and exit
Report bugs to http://code.google.com/p/trash-cli/issues
"""
print_differences(string1, string2)
Dieses so etwas gedruckt werden soll:
--- string1
+++ string2
@@ -1,6 +1,6 @@
Usage: trash-empty [days]
-Purge trashed files.
+Empty the trash can.
Options:
--version show program's version number and exit