def file_md5sum ( filename ) : hash_md5 = hashlib . md5 ( ) with open ( filename , 'rb' ) as f : for chunk in iter ( lambda : f . read ( 1024 * 4 ) , b'' ) : hash_md5 . update ( chunk ) return hash_md5 . hexdigest ( )
python chunked md5 sum save memory
: param filename : The filename of the file to process : returns : The MD5 hash of the file
def file_md5sum(filename):
    """
    :param filename: The filename of the file to process
    :returns: The MD5 hash of the file
    """
    hash_md5 = hashlib.md5()
    with open(filename, 'rb') as f:
        for chunk in iter(lambda: f.read(1024 * 4), b''):
            hash_md5.update(chunk)
    return hash_md5.hexdigest()