1. 程式人生 > >鐵樂學python_md5校驗兩個文件的一致性

鐵樂學python_md5校驗兩個文件的一致性

lib true 返回 code content 一個 ont HA pen

# 寫一個函數,參數是兩個文件的路徑
# 返回的結果是T/F
# 判斷兩個文件的md5值是否相同

import hashlib

def diff_md5(file1,file2):
    def chick_md5(file):
        md5 = hashlib.md5()
        with open(file, ‘rb‘) as f:
            while True:
                content = f.read(8192)
                if content:
                    md5.update(content)
                else
: break return md5.hexdigest() return chick_md5(file1) == chick_md5(file2)

2018-4-23
end

鐵樂學python_md5校驗兩個文件的一致性