Monday 16 March 2009

String table to list

a = file('filename')
b = a.readlines()
c = b[3:86] # extract relevant rows

# list of lists, assuming space separated values, stripping
# empty strings.

d = [[j for j in i.split(' ') if j != ''] for i in c] # lists of strings
d = [[float(j) for j in i.split(' ') if j != ''] for i in c] # lists of floats

d can be converted to an array, if desired. :)

No comments:

Post a Comment