代码之家  ›  专栏  ›  技术社区  ›  Nathan

我无法使用h5py读取数据。“无法创建组”

  •  1
  • Nathan  · 技术社区  · 13 年前

    我正试图在快速启动页面上完成这个琐碎的例子

    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")
    

    输出为

    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)
    

    我试着正确地做这件事了吗?

    1 回复  |  直到 13 年前
        1
  •  3
  •   unutbu    13 年前

    使用 'a' 模式附加到文件,并且不要将组命名为与数据集相同的名称:

    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")