filecmp.cmp() doesn't seem to do what it says in the documentation

tinnews at isbd.co.uk tinnews at isbd.co.uk
Mon Sep 6 13:18:34 EDT 2010


I'm using filecmp.cmp() to compare some files (surprise!).

The documentation says:-
    Unless shallow is given and is false, files with identical
    os.stat() signatures are taken to be equal.

I'm not setting shallow explicitly so it's True, thus the function
should be comparing the os.stat() results.  However this doesn't seem
to be the case as even if I touch one of the files to change it's
access/modification date filecmp.cmp() still returns True.

Here is an example:-

    chris$ python
    Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
    [GCC 4.4.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import filecmp
    >>> print filecmp.cmp("/media/disk/DCIM/103_FUJI/DSCF3084.JPG", "/home/chris/pictures/2010/4/24dscf3084.jpg")
    True
    >>> 
    chris$ ls -l /media/disk/DCIM/103_FUJI/DSCF3084.JPG /home/chris/pictures/2010/4/24dscf3084.jpg
    -rwxr-xr-x 1 chris chris 1783277 2010-09-06 17:36 /home/chris/pictures/2010/4/24dscf3084.jpg
    -rwxr-xr-x 1 chris root  1783277 2010-09-06 17:53 /media/disk/DCIM/103_FUJI/DSCF3084.JPG
    chris$ 

The file modification times are different, surely filecmp.cmp() should
be returning false.  I actually think the way it's working makes more
sense as I don't care if the modification time has changed if the
files are exactly the same length still.


-- 
Chris Green



More information about the Python-list mailing list