I want to read in a text file that is very poorly made in that the values in each line are sometimes not separated by spaces or commas (so i cant use .split()). I want to read it like you would in FORTRAN where I tell it exactly where each value is. This is what I am trying. Does anyone know a better approach to do this? Thanks !
f=open('f.out','r')
lines = f.readlines()
nLines = len(lines)
data = {}
keys = {'SPE':[0, 2, np.int], #I2
'SPEISO':[2, 3, np.int], #I1
'wnum':[3,15, np.float64], #F12.6
'S':[15, 25, np.float64], #E10.3
'Ecoeff':[25, 35, np.float64], #E10.3
'AGA':[35, 40, np.float64], #F5.5
'SGA':[40, 45, np.float64], #F5.4
'ELO':[45, 55, np.float64], #F10.4
'N' :[55, 59, np.float64], #F4.2
'FSH':[59, 67, np.float64], #F8.6
'TRS':[67, 127, np.str],
'IERR': [127, 133, np.int],
'IEFF': [133, 145, np.str],
'other': [145,160, np.str] }
for k in keys:
data[k] = np.zeros(nLines)
for i, l in enumerate(lines):
print i
for k in keys:
print k
data[[k][i]] = l.format(keys[k])