Any way to adjust difflib algorithm?

Grant Edwards invalid at invalid
Fri Aug 14 20:38:27 CEST 2009

I'm trying to use difflib to compare two files, and it's not
producing very useful results.  When comparing two lines where
only a few characters have changed, it usually seems to decide
that a line was deleted/inserted/replaced rather than changed.

Here's how I'm using it:

   import sys,difflib
   fromlines = [l.rstrip('\n') for l in open(sys.argv[1]).readlines()]
   tolines   = [l.rstrip('\n') for l in open(sys.argv[2]).readlines()]
   print difflib.HtmlDiff().make_file(fromlines,tolines)
In my particular usage, no lines have ever been
inserted/deleted, so perhaps I should be running diffs on
individual lines instead?  If I do that, I can't figure out how
to generate HTML output.

Is there a way to tell the differ to try harder to match lines?

Grant Edwards                   grante             Yow! I hope something GOOD
                                  at               came in the mail today so
                                 I have a REASON to live!!

More information about the Python-list mailing list