467,907 Members | 1,075 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,907 developers. It's quick & easy.

Generating side-by-side differences in HTML

The difflib.py module and the diff.py tools script in Python 2.4 alpha
3 now support generating side by side (with intra line differences) in
HTML format. I have found this useful for performing build release
comparisons (I use a script to generate a main page showing all the
files that were changed in a build with hyperlinks to side by side
differences for each of those files). I also find it useful for
generating HTML test reports to show differences between actual and
expected log files. In addition I use it for supplementing Doxygen
generated HTML with side by side differences of files that were

Example usages:

c:/python2x/Tools/Scripts/diff.py -m file1.txt file2.txt > some.html

import difflib
file1 = 'file1.txt'
file2 = 'file2.txt'
lines1 = open(file1).readlines()
lines2 = open(file2).readlines()
differ = difflib.HtmlDiff(tabsize=4,wrapcolumn=80)
html = differ.make_file(lines1,lines2,file1,file2,context =True,numlines=10)
f = open('some.html','w')

'tabsize' defaults to 8
'wrapcolumn' defaults to None (no line wrapping)
'context' defaults to False (shows full file vs. just showing diffs +
'numlines' defaults to 5

You can try out the code either by installing Python 2.4 alpha 3 or
you can obtain the patched files (and example output) from:

Dan Gass
Jul 18 '05 #1
  • viewed: 1619

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by paul | last post: by
3 posts views Thread by skn | last post: by
3 posts views Thread by Steve Dussinger | last post: by
7 posts views Thread by eric.gagnon | last post: by
6 posts views Thread by Poul Møller Hansen | last post: by
3 posts views Thread by Raed Sawalha | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.