hashlib 文件校验 # for循环校验 import hashlib def check_md5(file): ret = hashlib.md5() with open(file, mode='rb') as f1: for line in f1: ret.update(line) return ret.hexdigest() print(check_md5('rock1')) print(check_md5('rock')) print(check_md5('rock1') == ch