import numpy as np def is_float( s ): try: float(s) return True except ValueError: return False def loaddat( filename ): """ Load ascii data files into a numpy array """ mdata = {} tdata = [] for l in open( filename ) : if l.startswith( "#" ) : if ":" in l : tmp = [e.strip() for e in l[1:].partition(':')] mdata[tmp[0]] = tmp[2] elif l and not l.isspace() : vals = [ float( i ) for i in l.split() if is_float( i ) ] if len( vals ) > 0 : tdata.append( vals[0] ) elif len( tdata ) > 0 : break return tdata, mdata d,m = loaddat('../Pholidoptera_litoralis/Time_stamps/Chang/sychronization_2013-07-31-102053h_5-msec.dat') # the dictionary of meta data: print m print # use the value of a specific metadata item: print 'The animal number was: ', m['Animal'] print # the data array: print d print # the fifth value of the data array: print 'The sixth data value: ', d[0] print