You're not providing all the details, but i assume that:
- there's only 1 header line at the beginning and you don't need what's in it
- the other lines only contain integers
- you don't need to retain the trailing '0'
I have to also assume your file may be very big, so reading the entire file in memory, or storing the entire resulting list in memory is not a very good idea.
Here's a quick solution which reads the file line-by-line and uses a generator to yield each line as a list. You can use the entire result as one list if you want, like so:
result_list = read_data('foo.dat')
or you can do as i did in the example call and use each result line as it's read out. You can call this file directly if you're on linux, otherwise just associate it with the python interpreter, and call it with the name of the data file as the first argument, and it'll print the results line by line - this will work even if your file is humongous. You can also just import the file as a module and use the read_data method and use the results in other calculations.
Note that it does some error checking (the header line starts with a p and the data lines end with a 0, and only contain integers), and you probably want to either not do this checking at all, or raise a proper exception when they're encountered.
#!/usr/bin/env python
import sys
def read_data(fn):
"""Reads in datafile
data file is in format:
p wfgh 1111 11111 111111
287 48 0
65626 -1818 0
4654 21512 02020 0
where first line begins with p and is a header, and following lines
are comprised of at least 2 integers plus a tailing 0.
Pass in the filename, the resulting list of lists of integers will be
returned.
"""
f = open(fn, 'r')
# check for header line
assert(f.readline().split()[0]=='p')
for l in f:
d = [int(col) for col in l.split()]
if not d:
# skip empty lines
continue
# check we have at least 2 integers and the last column is 0
assert(d[-1] == 0 and len(d) >= 3)
# yield current line
yield d[:-1]
if __name__ == '__main__':
for l in read_data(sys.argv[1]):
print unicode(l)