I have a hdf5 file I want to modify by deleting an attribute of one of the datasets and save the file without further changes. I can do this in hdfview, but I need something that's scriptable because it needs to be applied to a large number of files.
I tried writing a script in python, using h5py:
import h5py
inF = h5py.File("Filename.h5", 'r')
dSet = inF['/data/myDataset']
del dSet.attrs['myAttrName']
But I get the following error:
Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/dist-packages/h5py/_hl/attrs.py", line 75, in delitem h5a.delete(self._id, self._e(name)) File "h5a.pyx", line 135, in h5py.h5a.delete (h5py/h5a.c:2682) KeyError: "unable to delete attribute (Attribute: Can't delete message)"
print dSet.attrs['myAttrName'] produces the correct value, proving I can access the attribute.
Is there any other ways to do this? Maybe using h5repack?