Python difflib gnu补丁兼容性

2024-10-03 06:22:08 发布

您现在位置:Python中文网/ 问答频道 /正文

可以用python模块difflib创建与GNU patch兼容的补丁? 我尝试使用统一的\u 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.

我用过文件.writelines(diff)将修补程序写入文件(代码段http://pastebin.com/3HAWfwVf

文件测试.txt公司名称:

^{pr2}$

文件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

谢谢你的帮助。在


Tags: 文件intesttxthelloisdiffthis
2条回答
  1. 尝试使用python-patch而不是GNU patch实用程序来应用统一差异
  2. 使用diff -rNau dir-v1/ dir-v2/ > 1-2.patch代替difflib。在

我将使用mercurialsbdiff模块,它比difflib快得多。在

相关问题 更多 >