python 比较2个文件内容

1. 通过使用md5字符串比较2个文件

import hashlib
def get_file_md5(filename):
    '''可以比较两个文件的md5值,来比较文件内容。未使用'''
    md5 = hashlib.md5()
    f = open(filename, 'rb')
    while True:
        b = f.read(8096)
        if not b:
            break
        md5.update(b)
    f.close()
    return md5.hexdigest()

python3

import filecmp
# true if 2 files are the same
result = filecmp.cmp(file1, file2)
原文地址:https://www.cnblogs.com/snow-backup/p/11726931.html