Sha sum files with Python

From PedrosBrainDump
import hashlib

def calculate_sha256(file_path):
    sha256_hash = hashlib.sha256()
    with open(file_path, "rb") as f:
        # Read and update hash string value in chunks of 4K
        for byte_block in iter(lambda: f.read(4096), b""):
            sha256_hash.update(byte_block)
    return sha256_hash.hexdigest()

# Usage
file_path = "path/to/your/file"
print("SHA-256:", calculate_sha256(file_path))