使用hashlib判断两个大文件的一致性
def file_md5(path): ''' 获取文件的md5 :param path:文件路径 :return: 返回密文 ''' import hashlib import os file_md5 = hashlib.md5() size = os.path.getsize(path) with open(path, mode='rb') as f: while size > 1024: content = f.read(1024) file_md5.update(content) size -= 1024 else: content = f.read(size) file_md5.update(content) size = 0 return file_md5.hexdigest()