Python difflib gnu 补丁兼容性

发布于 2024-12-02 03:34:12 字数 835 浏览 2 评论 0原文

可以使用与 GNU 补丁兼容的 python 模块 difflib 创建补丁吗? 我尝试使用 Unified_diff 和 context_diff 并尝试将 lineterm 指定为“\n”,但我仍然收到此错误:

[intense@Singularity Desktop]$ patch diff.patch test.txt 
patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.

我使用 file.writelines(diff) 将补丁写入文件(代码段 http://pastebin.com/3HAWfwVf)

文件 test.txt:

Hello, this is test
blah

文件 test2.txt:

Hello, this is test
blah, dfsgjdfgj
lfkdjgkldfjgkldfjgkl

并生成补丁:

--- /home/intense/Desktop/test.txt
+++ /home/intense/Desktop/test2.txt
@@ -1,2 +1,7 @@
-Hello, this is test
-blah+Hello,+this+is+test+blah,+dfsgjdfgj+lfkdjgkldfjgkldfjgkl

感谢您的帮助。

It's possible to create patch with python module difflib which is compatible with GNU patch?
I tried to use unified_diff and context_diff and also tried to specify lineterm as "\n" but I'm still gettings this error:

[intense@Singularity Desktop]$ patch diff.patch test.txt 
patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.

I used file.writelines(diff) to write patch into file (Piece of code http://pastebin.com/3HAWfwVf)

File test.txt:

Hello, this is test
blah

File test2.txt:

Hello, this is test
blah, dfsgjdfgj
lfkdjgkldfjgkldfjgkl

And generated patch:

--- /home/intense/Desktop/test.txt
+++ /home/intense/Desktop/test2.txt
@@ -1,2 +1,7 @@
-Hello, this is test
-blah+Hello,+this+is+test+blah,+dfsgjdfgj+lfkdjgkldfjgkldfjgkl

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

归途 2024-12-09 03:34:12

我会使用mercurials bdiff 模块,它比difflib 快得多。

I'd use mercurials bdiff module, which is considerably faster than difflib.

妄断弥空 2024-12-09 03:34:12
  1. 尝试使用 python-patch 而不是 GNU 补丁实用程序来应用统一差异,
  2. <强>或使用diff -rNau dir-v1/dir-v2/> 1-2.patch 而不是 difflib。
  1. Try to use python-patch instead of the GNU patch utility to apply unified diffs,
  2. OR use diff -rNau dir-v1/ dir-v2/ > 1-2.patch instead of difflib.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文