read file with multiple data per line

woooee at gmail.com woooee at gmail.com
Tue Apr 14 20:03:55 EDT 2009


If this is the record, then you can use split to get a list of the
individual fields and then convert to int or float where necessary.
rec = "2NHST1   C1   56   3.263   2.528  16.345 "
rec_split = rec.split()
print rec_split

If you want to read two records at a time, then use
all_data = open(name, "r").readlines()
to read all data into memory, given that the file isn't huge.  You can
then use a for loop, step=2, to access 2 records at a time.



More information about the Python-list mailing list