Skip to content

Instantly share code, notes, and snippets.

@gbishop
Created December 26, 2010 13:22
Show Gist options
  • Save gbishop/755418 to your computer and use it in GitHub Desktop.
Save gbishop/755418 to your computer and use it in GitHub Desktop.
Visually compare python objects with diff
from difflib import Differ
from pprint import pformat
def diff(o1, o2):
po1 = pformat(o1).splitlines()
po2 = pformat(o2).splitlines()
d = Differ()
r = [ line for line in d.compare(po1, po2) if line[0] in '+-' ]
return '\n'.join(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment