From: <phi...@ho...> - 2005-05-31 12:30:18
|
Hi list, I'm browsing an hdf5 file using pytables 1.0 with python 2.3 and fill a gtk treeview. I use a list composed with dictionaries to store the name and the type of node in the hdf5 file. Here is the method i use: def fill_treeview(self,filename=""): components_list=[] h5file = tables.openFile(filename, "a") for group in h5file.walkGroups("/"): components_list.append({'name':group._v_name,'type':"Group"}) for array in h5file.listNodes(group, classname = 'Array'): components_list.append({'name':array.hdf5name,'type':"Array"}) for Table in h5file.walkNodes(group, "Table"): components_list.append({'name':Table.hdf5name,'type':"Table"}) for i in range(len(components_list)): iter = self.__model.insert_before(None, None) self.__model.set_value(iter, 0, components_list[i]['name']) self.__model.set_value(iter, 1, components_list[i]['type']) I browsed the pytables several times. I didn't find a better way to do it. The problems are: - i use lots of for loop -that's a memory waste- - i use three differents functions to get the name of node (group._v_name, array.hdf5name, Table.hdf5name). Is it appropriate. - When i see the result, a table which is in a group is displayed also in the root node '/'. I don't know why. Is there a better way to do this? Perhaps it could be using only one loop with the node element? for node in h5file: ... In this case i don't know how to get the type of the node (i.e:Table,Array or Group). Thans a lot for your answers, Regards, Philippe Collet |