import numpy as np import h5py試み、返しerrorno = 17、エラーメッセージ=
with h5py.File("testfile.hdf5", "w-") as f: arr = np.ones((5,2)) f["my dataset"] = arr dset = f["my dataset"]
を「ファイルが存在している」このコードは正しく、初めてを実行しますが、2番目の時間を実行すると、次のエラーが返されます。
%run "C:\Users\James\Google Drive\Python Scripts\Python and HDF5\Chapter3.py" --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) C:\Users\James\Google Drive\Python Scripts\Python and HDF5\Chapter3.py in() 6 with h5py.File("testfile.hdf5") as f: 7 arr = np.ones((5,2)) ----> 8 f["my dataset"] = arr 9 dset = f["my dataset"] 10
h5py_objects.pyx in h5py._objects.with_phil.wrapper (C:\pisi\tmp\h5py-2.6.0-2\work\h5py-2.6.0\h5py_objects.c:2696)()
h5py_objects.pyx in h5py._objects.with_phil.wrapper (C:\pisi\tmp\h5py-2.6.0-2\work\h5py-2.6.0\h5py_objects.c:2654)()
C:\Users\James\AppData\Local\Enthought\Canopy\User\lib\site-packages\h5py_hl\group.py in setitem(self, name, obj) 291 else: 292 ds = self.create_dataset(None, data=obj, dtype=base.guess_dtype(obj)) --> 293 h5o.link(ds.id, self.id, name, lcpl=lcpl) 294 295 @with_phil
h5py_objects.pyx in h5py._objects.with_phil.wrapper (C:\pisi\tmp\h5py-2.6.0-2\work\h5py-2.6.0\h5py_objects.c:2696)()
h5py_objects.pyx in h5py._objects.with_phil.wrapper (C:\pisi\tmp\h5py-2.6.0-2\work\h5py-2.6.0\h5py_objects.c:2654)()
h5py\h5o.pyx in h5py.h5o.link (C:\pisi\tmp\h5py-2.6.0-2\work\h5py-2.6.0\h5py\h5o.c:3610)()
RuntimeError: Unable to create link (Name already exists)
%run "C:\Users\James\Google Drive\Python Scripts\Python and HDF5\Chapter3.py" --------------------------------------------------------------------------- IOError Traceback (most recent call last) C:\Users\James\Google Drive\Python Scripts\Python and HDF5\Chapter3.py in() 4 from timeit import timeit 5 ----> 6 with h5py.File("testfile.hdf5", "w-") as f: 7 arr = np.ones((5,2)) 8 f["my dataset"] = arr
C:\Users\James\AppData\Local\Enthought\Canopy\User\lib\site-packages\h5py_hl\files.py in init(self, name, mode, driver, libver, userblock_size, swmr, **kwds) 270 271 fapl = make_fapl(driver, libver, **kwds) --> 272 fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr) 273 274 if swmr_support:
C:\Users\James\AppData\Local\Enthought\Canopy\User\lib\site-packages\h5py_hl\files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr) 94 fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl) 95 elif mode in ['w-', 'x']: ---> 96 fid = h5f.create(name, h5f.ACC_EXCL, fapl=fapl, fcpl=fcpl) 97 elif mode == 'w': 98 fid = h5f.create(name, h5f.ACC_TRUNC, fapl=fapl, fcpl=fcpl)
h5py_objects.pyx in h5py._objects.with_phil.wrapper (C:\pisi\tmp\h5py-2.6.0-2\work\h5py-2.6.0\h5py_objects.c:2696)()
h5py_objects.pyx in h5py._objects.with_phil.wrapper (C:\pisi\tmp\h5py-2.6.0-2\work\h5py-2.6.0\h5py_objects.c:2654)()
h5py\h5f.pyx in h5py.h5f.create (C:\pisi\tmp\h5py-2.6.0-2\work\h5py-2.6.0\h5py\h5f.c:2109)()
IOError: Unable to create file (Unable to open file: name = 'testfile.hdf5', errno = 17, error message = 'file exists', flags = 15, o_flags = 502)
コードとエラーはCanopy // Python 3.5で実行されました。私もSpyderで走り、同じ結果を得ました。私も使用しようとしました
with h5py.File("testfile.hdf5", "a") as f:
成功しません。