heychenbin
1/27/2014 - 3:15 AM

对文件求md5值

对文件求md5值

import hashlib

def md5_file(f):
    m = hashlib.md5()
    with open(f, 'rb') as fd:
        while True:
            d = fd.read(8192)           # 一次读取8k
            if not d:
                break
            m.update(d)
    return m.hexdigest()