Python Forum

Full Version: Check if a Group/dataset path exists
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi

I'm working on hdf5 files having group and subgroups, so I'm providing the path to the datasets or the groups. In practise, I know how to check if a group and/or a dataset exists using ".keys()", but is it possible to check if the path (or an object) exists or not?

I've been digging in the doc, but still looking for the answer

Thanks

The following generates an error since the path is not valid
    if hdf5['MyPath']:
        print("ok Path exists")
Error:
KeyError: "Unable to open object (object 'MyPath' doesn't exist)"