问题
I want to read the HDF5 file into Python and do some coding work. To access the data in HDF5 file in python environment, you need dataset name of HDF5 file. However, I do not know how to find the dataset name and I would like to ask for help.
def select_HDF_file(self):
filename2 = QFileDialog.getOpenFileName(self.dlg, "Select output
file","",'*.hdf')
dataset_name = '**************'
file = h5py.File(filename2 , 'r')
dataset = file[dataset_name]
回答1:
file is a python dictionary. Thus you can iterate over file and stock all datasets for example:
>>> file = h5py.File('file.h5', 'r')
>>> dataset = []
>>> for i in file.values():
... dataset.append(i)
... ...
If just for the list: list(file.values()).
Finally, if you just want the name of the datasets then:
list(file.keys())
['Patch_001-inlet', 'Patch_002-outlet', 'Patch_003-wall']
来源:https://stackoverflow.com/questions/45280185/how-to-know-hdf5-dataset-name-in-python