遍历file的方式
复制代码
1iter(lambda: f.read(4096), "")
等价与
while True:
data = f.read(4096)
if not data:
break
hash_md5.updata(data)
复制代码
1
2
3
4
5
6
7
8
9# 生成md5 def get_file_md5(fname): hash_md5 = hashlib.md5() with open(fname, "rb") as f: print type(f) for chunk in iter(lambda: f.read(4096), ""): hash_md5.update(chunk) return base64.b64encode(hash_md5.digest())
转载于:https://www.cnblogs.com/bierxiaobia/p/6434555.html
最后
以上就是大方世界最近收集整理的关于python read文件内容的iter方式的全部内容,更多相关python内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复