411 REFERENCE · Wikibooks
Python 3: working with files and digital assets/File/Hashing
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Hashing of Files
pip install pillow
pip install requests
%pip install pillow
%pip install requests
import hashlib
def hash_file_sha1(
location_of_file: str
) -> str:
value: str | None = None
hash_algorithm = hashlib.sha1()
with open(
location_of_file,
'rb'
) as file:
chunk = 0
while chunk != b'':
chunk = file.read(1024)
hash_algorithm.update(chunk)
value = str(
hash_algorithm.hexdigest()
)
return value