diff --brief

Thomas Güttler guettler at thomas-guettler.de
Fri Jun 6 16:19:02 CEST 2003


Hi!

I need a method like diff --brief which tells my
wether two files differ.

I looked at filecmp.cmp(), but this does not seem
to do what I want.

I did it like this, but I would prefere to use a function
from the library (if there is such a function)

def diff(file1, file2):
    """
    returns 1 if the content of both files are different
    returns 0 if all bytes are equal.
    """
    fd1=open(file1)
    fd2=open(file2)
    while 1:
        chunk1=fd1.read(1024)
        chunk2=fd2.read(1024)
        if not chunk1:
            if chunk2:
                return 1
            else:
                break
        if chunk1!=chunk2:
            return 1
    return 0
        





More information about the Python-list mailing list