I'm trying to complete the trivial example on the quickstart page

http://www.h5py.org/docs/intro/quick.html

import h5py
f = h5py.File('myfile.hdf5','w')
dset = f.create_dataset("MyDataset", (100, 100), 'i')
dset[...] = 42
f.close()

ff = h5py.File('myfile.hdf5','r')
dset = ff.create_group("MyDataset")

output is

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/h5py/_hl/group.py", line 28, in create_group
    gid = h5g.create(self.id, name, lcpl=lcpl)
  File "h5g.pyx", line 135, in h5py.h5g.create (h5py/h5g.c:2057)
ValueError: unable to create group (Symbol table: Unable to initialize object)

Am I trying to do this correctly?

有帮助吗?

解决方案

Use 'a' mode to append to the file, and do not name the group the same name as the dataset:

import h5py
with h5py.File('myfile.hdf5','w') as f:
    dset = f.create_dataset("MyDataset", (100, 100), 'i')
    dset[...] = 42

with h5py.File('myfile.hdf5','r+') as ff:
    dset = ff.create_group("MyGroup")
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top