在python中生成和应用差异 [英] Generating and applying diffs in python

查看:74
本文介绍了在python中生成和应用差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

python中是否有一种开箱即用的方法来生成两个文本之间的差异列表,然后将此差异应用于一个文件以获得另一个文件?

Is there an 'out-of-the-box' way in python to generate a list of differences between two texts, and then applying this diff to one file to obtain the other, later?

我想保留文本的修订历史记录,但是如果只有一个编辑行,我不想为每个修订版本保存整个文本。我查看了 difflib ,但我看不到如何生成仅编辑的行仍然可以用来修改一个文本以获得另一个文本。

I want to keep the revision history of a text, but I don't want to save the entire text for each revision if there is just a single edited line. I looked at difflib, but I couldn't see how to generate a list of just the edited lines that can still be used to modify one text to obtain the other.

推荐答案

您是否已看过diff-match -来自Google的补丁?显然,谷歌文档使用这套算法。它不仅包括一个diff模块,还包括一个补丁模块,因此您可以从较旧的文件和diff生成最新文件。

Did you have a look at diff-match-patch from google? Apparantly google Docs uses this set of algoritms. It includes not only a diff module, but also a patch module, so you can generate the newest file from older files and diffs.

其中包含python版本。

A python version is included.

http:// code .google.com / p / google-diff-match-patch /

这篇关于在python中生成和应用差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆