grid_search.py 文件源码

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

项目:data_utilities 作者: fmv1992 项目源码 文件源码
def get_hash(self, x):
        # TODO: cached for strings and paths.
        # Need to generalize the reading of:
        #   1) file paths
        #   2) small strings
        #   3) python_objects
        if isinstance(x, (dict, bytes)) or not os.path.isfile(x):  # use function cache.
            return self._get_hash_from_hashable(self._transform_to_hashable(x))
        # For files.
        hash_obj = self.hash_function()
        iter_of_bytes = open(x, 'rb')
        try:
            data = iter_of_bytes.read(io.DEFAULT_BUFFER_SIZE)
            while data:
                hash_obj.update(data)
                data = iter_of_bytes.read(io.DEFAULT_BUFFER_SIZE)
        finally:
            iter_of_bytes.close()
        return hash_obj.digest()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号