visiting all datasets in HDF file and return a list

I wish to recursively visit all the Datasets in an HDF5 file and return a list of all their names. I’ve gotten the “visititems()” method to work if I merely want to print a list but I’m not sure how I modify visititems() to return an actual Python list rather than just printing it. I want to retrieve an actual list of the Datasets in the file and then iterate over that list later in the program.

visititems() seems like it’s limited to only having (name, object) in the calling interface and returning a list will cause it to terminate early.

Any good ideas for working my way around these limitations?

Catherine, except for a check on the object type, I don’t see much that is specific to HDF5 in your question. Have you considered a variation of say https://thispointer.com/python-how-to-get-list-of-files-in-directory-and-sub-directories/ ?

G.

Hi G,

I was looking for a way of using the “visit” functions in h5py to return an actual Python list holding the names of all the datasets in a file but it seems like the two “visit” functions are hardwired in terms of their interface and cannot be expanded upon.

In the end, I “rolled my own” code to accomplish this task and it seems to be working just fine.

Catherine