binary file compare...

Steven D'Aprano steve at
Tue Apr 14 02:05:52 CEST 2009

On Mon, 13 Apr 2009 15:03:32 -0500, Grant Edwards wrote:

> On 2009-04-13, SpreadTooThin <bjobrien62 at> wrote:
>> I want to compare two binary files and see if they are the same. I see
>> the filecmp.cmp function but I don't get a warm fuzzy feeling that it
>> is doing a byte by byte comparison of two files to see if they are they
>> same.
> Perhaps I'm being dim, but how else are you going to decide if two files
> are the same unless you compare the bytes in the files?

If you start with an image in one format (e.g. PNG), and convert it to 
another format (e.g. JPEG), you might want the two files to compare equal 
even though their byte contents are completely different, because their 
contents (the image itself) is visually identical.

Or you might want a heuristic as a short cut for comparing large files, 
and decide that if two files have the same size and modification dates, 
and the first (say) 100KB are equal, that you will assume the rest are 
probably equal too.

Neither of these are what the OP wants, I'm just mentioning them to 
answer your rhetorical question :)


More information about the Python-list mailing list