h5.py 文件源码

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

项目:klusta 作者: kwikteam 项目源码 文件源码
def read_attr(self, path, attr_name, default=False):
        """Read an attribute of an HDF5 group."""
        _check_hdf5_path(self._h5py_file, path)
        attrs = self._h5py_file[path].attrs
        if attr_name in attrs:
            try:
                out = attrs[attr_name]
                if (isinstance(out, (np.ndarray, np.generic)) and
                        out.dtype.kind == 'S'):
                    out = out.tostring().decode('UTF-8')
                    out = out.replace('\x00', '')
                return out
            except (TypeError, IOError):
                logger.debug("Unable to read attribute `%s` at `%s`.",
                             attr_name, path)
                return
        elif default is False:
            raise KeyError("The attribute '{0:s}' ".format(attr_name) +
                           "at `{}` doesn't exist.".format(path))
        return default
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号