【发布时间】:2016-08-07 16:57:52
【问题描述】:
我有一个非常奇怪的问题。我有 2 个函数:一个读取使用 h5py 创建的 HDF5 文件,另一个创建一个新的 HDF5 文件,该文件连接前一个函数返回的内容。
def read_file(filename):
with h5py.File(filename+".hdf5",'r') as hf:
group1 = hf.get('group1')
group1 = hf.get('group2')
dataset1 = hf.get('dataset1')
dataset2 = hf.get('dataset2')
print group1.attrs['w'] # Works here
return dataset1, dataset2, group1, group1
还有创建文件功能
def create_chunk(start_index, end_index):
for i in range(start_index, end_index):
if i == start_index:
mergedhf = h5py.File("output.hdf5",'w')
mergedhf.create_dataset("dataset1",dtype='float64')
mergedhf.create_dataset("dataset2",dtype='float64')
g1 = mergedhf.create_group('group1')
g2 = mergedhf.create_group('group2')
rd1,rd2,rg1,rg2 = read_file(filename)
print rg1.attrs['w'] #gives me <Closed HDF5 group> message
g1.attrs['w'] = "content"
g1.attrs['x'] = "content"
g2.attrs['y'] = "content"
g2.attrs['z'] = "content"
print g1.attrs['w'] # Works Here
return mergedhf.get('dataset1'), mergedhf.get('dataset2'), g1, g2
def calling_function():
wd1, wd2, wg1, wg2 = create_chunk(start_index, end_index)
print wg1.attrs['w'] #Works here as well
现在的问题是,我可以访问由 wd1、wd2、wg1 和 wg2 创建和表示的新文件中的数据集和属性,并且我可以访问属性数据,但我不能这样做读取并返回值。
当我返回对调用函数的引用后,谁能帮我获取数据集和组的值?
【问题讨论】:
标签: python python-2.7 hdf5 h5py