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
评论列表
文章目录