Skip to content

Instantly share code, notes, and snippets.

@deehzee
Last active February 8, 2017 13:15
Show Gist options
  • Save deehzee/af06125de8565dd6305e425ce56fdbd5 to your computer and use it in GitHub Desktop.
Save deehzee/af06125de8565dd6305e425ce56fdbd5 to your computer and use it in GitHub Desktop.
Compute MD5SUM of a File in Python
# Compute md5sum of a file
# File: md5sum.py
# Debajyoti Nandi
# 2016-11-09
# Python 2
import os
import hashlib
def md5sum(fname):
"""Find the md5sum hash of the content of a given file."""
blocksize = 65536
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for block in iter(lambda: f.read(blocksize), b""):
hash_md5.update(block)
return hash_md5.hexdigest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment