【发布时间】:2021-07-24 09:02:04
【问题描述】:
我想用 h5py 将一个很长的文件路径作为字符串保存在我的 hdf5 中。我有以下代码,但它似乎不起作用。当我读取文件时,变量不显示文件路径。 请问怎么做比较好?谢谢。
import h5py
hdf5filename='testhdf5.h5'
hdf5dsetname_origin="/entry/origin/filename"
# create hdf5 file and store a very long file path
with h5py.File(hdf5filename, "w") as h5f:
string_dt = h5py.special_dtype(vlen=str)
h5f.create_dataset(hdf5dsetname_origin, data='/path/to/data/verylong/verylong/verlong/extralong',dtype=string_dt)
# read it and check the file path
with h5py.File(hdf5filename,"r") as h5:
string=h5["/entry/origin/filename"]
print(string)
【问题讨论】:
标签: python-3.x hdf5 h5py