通过md5校验文件,我们可以判断文件内容是否改变,用python实现代码如下
import hashlib
# 1.txt为空文本
with open('1.txt', 'rb') as f:
data = f.read()
md5Old = hashlib.md5(data).hexdigest()
print(md5Old) # d41d8cd98f00b204e9800998ecf8427e
# 1.txt内容为123
with open('1.txt', 'rb') as f:
data = f.read()
md5New = hashlib.md5(data).hexdigest()
print(md5New) # 202cb962ac59075b964b07152d234b70
标签:hashlib,python,校验,md5Old,txt,data,md5
From: https://www.cnblogs.com/wstong2052/p/17652823.html