title: Python: How to compare two binary files?
body: <p>In python I need to print a diff of two binary files. I was looking at <code>difflib.Differ</code> which does a lot.</p>
  
  <p>However differ assumes lines of text and so the output does not list the byte index and the hex value difference.</p>
  
  <p>What I need is output that has what byte is different, how the byte is different, the actual hex values of the two bytes.</p>
  
  <p><strong>In Python, how do you compare two binary files (output: the byte diff index, the hex values of the two bytes)?</strong></p>
  
  <p>I was doing something like:</p>
  
  <pre><code># /usr/bin/env python2
  import difflib
  x = open('/path/to/file1', 'r').read()
  y = open('/path/to/file2', 'r').read()
  print '\n'.join(difflib.Differ().compare(x, y))
  </code></pre>
  
  <p>But this doesn't output the byte index where the difference is. And it doesn't print the hex values.</p>