Best way of comparing two files in python and why? : <p>I have two files a.txt and b.txt, So i am trying to compare using hash like below.</p>

<pre><code>#getting hash of files and comparing
file1 = hashlib.md5(open('a.txt', 'rb').read()).hexdigest()
file2 = hashlib.md5(open('b.txt', 'rb').read()).hexdigest() 
file1==file2--&gt; returns True or False
</code></pre>

<p>this is one way and also we can do using filecmp as below</p>

<pre><code>filecmp.cmp('a.txt','b.txt')--&gt; returns True or False
</code></pre>

<p>In both of these ways which is better and why?</p>
