By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,317 Members | 2,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,317 IT Pros & Developers. It's quick & easy.

Generating side-by-side differences in HTML

P: n/a
The module and the 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/ -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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.