我正在尝试合并一个文件以及对其进行的一些更改。 例如,如果我有文件:
This is Line 1
This is Line 2
This is Line 3
我已将其更改为:
This is Line 1
This is Line 3
This one is another line
我将从 difflib.unified_diff
获得此输出:
--- test.txt
+++ test2.txt
@@ -29,1 +29,1 @@
-2+3@@ -36,0 +36,4 @@
+o+n+e+ @@ -39,1 +43,9 @@
-L+a+n+o+t+h+e+r+ +l@@ -43,2 +55,0 @@
- -3
我希望能够仅获取此输出和原始文件,并将它们合并以获取第二个文件。
有什么办法可以实现这个目标吗?
最佳答案
最后我找到了一个名为“diff_match_patch”的库,它正是我一直在寻找的东西。 在这里查看更多信息: https://code.google.com/archive/p/google-diff-match-patch/
关于python - 在 Python 中将文件和差异合并到一个新文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35451180/