Skip to main content
 首页 » 编程设计

python之您可以使用组对象提取 hdf5 的文件对象吗

2024年12月31日998°冷暖

我在 ipython 中打开了一个 hdf5 文件,使用

import h5py as h5 
f = h5.File("fname.h5", "r") 

然后我访问了那个文件中的一个组

g1 = f['group1'] 

然后我不小心用另一个文件覆盖了f。第一个文件仍然打开,我可以访问 g1 中的内容,但我无法访问 f 中的任何其他组。有没有办法使用 g1 取回文件对象?当然我可以直接关闭文件再打开,但我想知道是否有其他方法。

请您参考如下方法:

您可以使用组的file 属性:

f = g1.file 

根据 docs对于 Group 属性:

file
File instance in which this group resides.