【发布时间】:2019-02-18 07:18:09
【问题描述】:
我正在尝试使用修改后的缓存设置创建 hdf5 文件处理程序,如下所示:
import h5py
import contextlib
def hdf5_handler(filename, mode="r"):
h5py.File(filename, "a").close()
propfaid = h5py.h5p.create(h5py.h5p.FILE_ACCESS)
settings = list(propfaid.get_cache())
settings[1] = 0
settings[2] = 0
propfaid.set_cache(*settings)
with contextlib.closing(h5py.h5f.open(filename, fapl=propfaid)) as fid:
return h5py.File(fid, mode)
#############
hdf5 = hdf5_handler("/tmp/foo.hdf5", "a")
但它给出了以下错误:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-121-35fa9f73a406> in <module>()
99 return h5py.File(fid, mode)
100 #############
--> 101 hdf5 = hdf5_handler("/tmp/foo.hdf5", "a")
<ipython-input-121-35fa9f73a406> in hdf5_handler(filename, mode)
96 settings[2] = 0
97 propfaid.set_cache(*settings)
---> 98 with contextlib.closing(h5py.h5f.open(filename, fapl=propfaid)) as fid:
99 return h5py.File(fid, mode)
100 #############
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/h5f.pyx in h5py.h5f.open()
TypeError: expected bytes, str found
Python 版本:3.5.5 h5py 版本:'2.8.0'
我还在下面找到了类似的代码,但同样的错误也不适用于我: How to set cache settings while using h5py high level interface?
【问题讨论】:
-
试试:
hdf5 = hdf5_handler(bytes("/tmp/foo.hdf5",encoding="utf-8"), "a") -
是的,谢谢,可以的
-
发生了什么变化?为什么在之前的 SO 帖子中他们没有使用字节?
-
我不知道。我认为他们正在使用其他 python 版本。
标签: python hdf5 h5py low-level