Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Create a Hash of a File
import os
import hashlib
def sha256sum(filename):
Create a file hash
:param: str (file path)
:return: str (md5 hash)
h = hashlib.sha256()
b = bytearray(128*1024)
mv = memoryview(b)
with open(filename, 'rb', buffering=0) as f1:
for n in iter(lambda : f1.readinto(mv), 0):
return h.hexdigest()
filehash = sha256sum(os.getcwd() + '/' + 'fourletterwords.txt')
print('File Hash: {}'.format(filehash))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.