Changeset 520
- Timestamp:
- May 3, 2011 10:50:38 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
hdf5_exchange/h5py_examples/src/h5toText/h5toText.py
r240 r520 2 2 3 3 ''' 4 Created on Dec 17, 2010 5 6 @author: prjemian 4 Print the structure of an HDF5 file to stdout 5 6 $Id$ 7 ''' 8 9 7 10 ########### SVN repository information ################### 8 11 # $Date$ … … 12 15 # $Id$ 13 16 ########### SVN repository information ################### 14 ''' 17 15 18 16 19 import h5py … … 21 24 22 25 class H5toText(object): 23 ''' classdocs ''' 26 ''' 27 Example usage showing default display:: 28 29 mc = H5toText(filename) 30 mc.array_items_shown = 5 31 mc.report() 32 ''' 24 33 filename = None 25 34 requested_filename = None … … 72 81 print indentation + name + nxclass 73 82 self.showAttributes(obj, indentation) 74 for name, value in obj.items(): 75 #print name, type(value) 76 if str(type(value)) in ("<class 'h5py.highlevel.File'>", "<class 'h5py.highlevel.Group'>"): 77 self.showGroup(value, name, indentation = indentation+" ") 78 else: 79 self.showDataset(value, name, indentation = indentation+" ") 83 group_equivalents = ("<class 'h5py.highlevel.File'>", "<class 'h5py.highlevel.Group'>") 84 # show datasets (and links) first 85 for itemname in sorted(obj): 86 value = obj[itemname] 87 if str(type(value)) not in group_equivalents: 88 self.showDataset(value, itemname, indentation = indentation+" ") 89 # then show things that look like groups 90 for itemname in sorted(obj): 91 value = obj[itemname] 92 if str(type(value)) in group_equivalents: 93 self.showGroup(value, itemname, indentation = indentation+" ") 80 94 81 95 def showAttributes(self, obj, indentation = " "): 96 '''print any attributes''' 82 97 for name, value in obj.attrs.iteritems(): 83 98 print "%s @%s = %s" % (indentation, name, str(value)) 84 99 85 100 def showDataset(self, dset, name, indentation = " "): 101 '''print the contents and structure of a dataset''' 86 102 shape = dset.shape 87 103 if self.isNeXus:
Note: See TracChangeset
for help on using the changeset viewer.