code: def get_hash(path, form='sha1', chunk_size=4096):
      '''
      Generate a hash digest string for a file.
      '''
      try:
          hash_type = getattr(hashlib, form)
      except AttributeError:
          raise ValueError('Invalid hash type: {0}'.format(form))
      with open(path, 'rb') as ifile:
          hash_obj = hash_type()
          # read the file in in chunks, not the entire file
          for chunk in iter(lambda: ifile.read(chunk_size), b''):
              hash_obj.update(chunk)
          return hash_obj.hexdigest(f get_hash(path, form='sha1', chunk_size=4096):
      '''
      Generate a hash digest string for a file.
      '''
      try:
          hash_type = getattr(hashlib, form)
      except AttributeError:
          raise ValueError('Invalid hash type: {0}'.format(form))
      with open(path, 'rb') as ifile:
          hash_obj = hash_type()
          # read the file in in chunks, not the entire file
          for chunk in iter(lambda: ifile.read(chunk_size), b''):
              hash_obj.update(chunk)
          return hash_obj.hexdigest()
docs: Generate a hash digest string for a file.