Changeset 520


Ignore:
Timestamp:
May 3, 2011 10:50:38 AM (12 years ago)
Author:
jemian
Message:

show datasets before groups at each level

File:
1 edited

Legend:

Unmodified
Added
Removed
  • hdf5_exchange/h5py_examples/src/h5toText/h5toText.py

    r240 r520  
    22
    33'''
    4 Created on Dec 17, 2010
    5 
    6 @author: prjemian
     4Print the structure of an HDF5 file to stdout
     5
     6$Id$
     7'''
     8
     9
    710########### SVN repository information ###################
    811# $Date$
     
    1215# $Id$
    1316########### SVN repository information ###################
    14 '''
     17
    1518
    1619import h5py
     
    2124
    2225class 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    '''
    2433    filename = None
    2534    requested_filename = None
     
    7281        print indentation + name + nxclass
    7382        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+"  ")
    8094
    8195    def showAttributes(self, obj, indentation = "  "):
     96        '''print any attributes'''
    8297        for name, value in obj.attrs.iteritems():
    8398            print "%s  @%s = %s" % (indentation, name, str(value))
    8499
    85100    def showDataset(self, dset, name, indentation = "  "):
     101        '''print the contents and structure of a dataset'''
    86102        shape = dset.shape
    87103        if self.isNeXus:
Note: See TracChangeset for help on using the changeset viewer.