Search code examples
pythonmatlabpython-3.xh5py

How to inspect .h5 file in Python


How do I see what variables, datasets, etc. a given .h5 file has in Python?

I can read the file by running this

import h5py
f = h5py.File(filename, 'r')

How can I now see which variables my .h5 file have?

Running f.keys() outputs the non-informative

KeysView(<HDF5 file filename (mode r)>)

In Matlab I simply call h5disp(filename) but would like to know how to do it in Python


Solution

  • Did you try?

    print(list(f.keys()))
    

    That should give you all the group inside your hdf5 file. You can do the same for the datasets if f is a group.