util.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:observations 作者: edwardlib 项目源码 文件源码
def get_file_hash(path, algorithm='md5'):
  """Get hash from a given file and hashing algorithm.

  Args:
    path: str.
      Full path to a file.
    algorithm: str, optional.
      Name of hashing algorithm. See `hashlib.algorithms_available`
      for list of available hashing algorithms in python.

  Returns:
    str. File hash computed from the file using the specified algorithm.

  #### Examples

  ```python
  get_file_hash('train.gz')
  ## '5503d900f6902c61682e6b6f408202cb'

""" hash_alg = hashlib.new(algorithm) with open(path, 'rb') as f: read_size = 1024 1024 4 data = f.read(read_size) while data: hash_alg.update(data) data = f.read(read_size) return hash_alg.hexdigest() ```

评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号