python - 在 Python 中生成文本修订历史的 View

标签 python diff history revision

我有一段文本的两个版本,我想生成其修订版的 HTML View ,类似于 Google Docs 或 Stack Overflow 显示的内容。我需要在 Python 中执行此操作。我不知道这种技术叫什么,但我假设它有一个名字,希望有一个 Python 库可以做到这一点。

版本 1:

William Henry "Bill" Gates III (born October 28, 1955)[2] is an American business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen.

版本 2:

William Henry "Bill" Gates III (born October 28, 1955)[2] is a business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen. He is American.

期望的输出:

William Henry "Bill" Gates III (born October 28, 1955)[2] is an American business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen. He is American.

使用 diff 命令不起作用,因为它告诉我哪些行不同,但没有告诉我哪些列/词不同。

$ echo 'William Henry "Bill" Gates III (born October 28, 1955)[2] is an American business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen.' > oldfile
$ echo 'William Henry "Bill" Gates III (born October 28, 1955)[2] is a business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen.  He is American.' > newfile
$ diff -u oldfile newfile
--- oldfile 2010-04-30 13:32:43.000000000 -0700
+++ newfile 2010-04-30 13:33:09.000000000 -0700
@@ -1 +1 @@
-William Henry "Bill" Gates III (born October 28, 1955)[2] is an American business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen.
+William Henry "Bill" Gates III (born October 28, 1955)[2] is a business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen.  He is American.' > oldfile

最佳答案

Google Diff Merge Patch在纯 python 中有一个很好的 diff 实现。

关于python - 在 Python 中生成文本修订历史的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2747600/

相关文章:

python - GDB+Python : Determining target type

python - 设置QBoxLayout最大尺寸?

python - 我需要在 python 中运行 TCL 脚本,我的 TCL 脚本还有一个用户定义的(内部)包

python - 你如何解析用 pysvn 创建的 diff 文件?

svn重新设定基准并丢失历史记录

python - Pandas ,处理 "Out of bounds timestamp..."

diff - 重击 : comm (or similar) when compare multiple files

git - 如何在 git add 交互式补丁模式中获得更好的帅哥?

java - 在 Eclipse 中重命名和重构类,并保留 SVN 历史记录

sql-server - 员工表(主表和明细表)