I'm trying to make function VisitAllObjects accept different files and return a dictionary. But what I have currently points to the same name? So once gdata is ran, fdata changes to gdata. How can I make it so fdata and gdata equal their respected data from their gh5 files?
f = h5py.File('testfile.gh5', 'r')
g = h5py.File('testfile2.gh5', 'r')
def VisitAllObjects(Group,Path, FileInfo=None):
if FileInfo is None:
FileInfo = {}
for i in Group.items():
if isinstance(i[1], h5py.Group):
VisitAllObjects(i[1], Path + '/' + i[0])
else:
DatasetName = Path + '/' + i[0]
FileInfo[DatasetName] = (Group[DatasetName].shape, Group[DatasetName].dtype)
return FileInfo
fdata = VisitAllObjects(f,'')
gdata = VisitAllObjects(g,'')
With your help and adding file_info when calling visit_all_objects within itself I was able to get this to work. If you see any problems with this please let me know, I still need to check it more but using fdata and gdata come back with different data and fdata is gdata
is False. Thanks.
I got it to work with the following:
def visit_all_objects(Group,Path, file_info=None):
if file_info is None:
file_info = {}
for i in Group.items():
if isinstance(i[1], h5py.Group):
visit_all_objects(i[1], Path + '/' + i[0], file_info)
else:
DatasetName = Path + '/' + i[0]
file_info[DatasetName] = (Group[DatasetName].shape, Group[DatasetName].dtype)
return file_info