Diff of Text

Lie Ryan lie.1296 at gmail.com
Sat Jun 5 03:53:32 EDT 2010


On 06/05/10 15:43, GZ wrote:
> On Jun 4, 8:37 pm, Lie Ryan <lie.1... at gmail.com> wrote:
>> On06/05/10 07:51, GZ wrote:
>>> No, rsync does not solve my problem.
>>
>>> I want a library that does unix 'diff' like function, i.e. compare two
>>> strings line by line and output the difference. Python's difflib does
>>> not work perfectly for me, because the resulting differences are
>>> pretty big. I would like an algorithm that generates the smallest
>>> differences.
>>
>> is n=0 not short enough?
>>
>> pprint.pprint(list(difflib.context_diff(s, t, n=0)))
> 
> This still does not do what I want it to do. It only displays the diff
> results in a different format. I want a different algorithm to
> generate a smaller diff -- in other words less differences

No, I meant I was confirming that you already have turned off context
lines (i.e. the n=0 part), right?



Also, what's the nature of the changes? You might be able to minimize
difflib's output by using word-based or character-based diff-ing instead
of traditional line-based diff-ing.



diff output is fairly compressable, so you might want to look at zipping
the output.



More information about the Python-list mailing list