reading a column from a file

pyGuy Mike.S.Duffy at gmail.com
Mon May 8 02:54:08 EDT 2006


f = open("datafile.txt", "r")
data = [line.split('\t') for line in f]
f.close()
pressure = [float(d[1]) for d in data]
temp = [float(d[2]) for d in data]
---------------------------------------------------

This will parse the file into a matrix stored in 'data'. The last two
lines simply iterate through second and third columns respectively,
converting each element to a float (from string as it was read in from
file) and assign to the appropriate vars.




More information about the Python-list mailing list