import difflib
import sys
fromfile = 'xxx'
tofile = 'zzz'
fromlines = open(fromfile, 'U').readlines()
tolines = open(tofile, 'U').readlines()
diff = difflib.HtmlDiff().make_file(fromlines, tolines, fromfile, tofile)
sys.stdout.writelines(diff)
Generate pretty diff html in Python