Python 关闭文件后,如何在内存中保留h5py组?

Python 关闭文件后,如何在内存中保留h5py组?,python,h5py,Python,H5py,关闭文件后,如何在内存中保留h5py组 在以下代码之后: import h5py feature_file = h5py.File(worm_file_path, 'r') worm_features = feature_file["worm"] 我可以访问worm\u功能,因为它是() 但在我跑完这条线之后: feature_file.close() 我无法再访问worm\u功能。它现在显示为 因为我需要为大约20个文件加载worm_features h5py组,所以我希望在处理加载到内

关闭文件后,如何在内存中保留h5py组

在以下代码之后:

import h5py

feature_file = h5py.File(worm_file_path, 'r')
worm_features = feature_file["worm"]
我可以访问worm\u功能,因为它是(

但在我跑完这条线之后:

feature_file.close()
我无法再访问
worm\u功能
。它现在显示为


因为我需要为大约20个文件加载worm_features h5py组,所以我希望在处理加载到内存中的数据之前关闭这些文件。这不可能吗?

使用.value从数据集中提取所需的变量

例如:

import h5py

feature_file = h5py.File(worm_file_path, 'r')
worm_features = feature_file["worm"].value
feature_file.close()
print worm_features

使用
[:]
将数据集的值复制到变量,以便在关闭hdf5文件后访问数据集

import h5py

feature_file = h5py.File(worm_file_path, 'r')
worm_features = feature_file["worm"] [:]
feature_file.close()
print (worm_features)
.value
对我无效,并引发以下错误:

AttributeError: 'Dataset' object has no attribute 'value'

仅定义
worm\u功能
不会将组的数据加载到内存中。您必须首先分配其所有数据集的
.value
(或
[:]
)。如何仅从其中一个文件加载和处理?