I think the pythonic way to do this is to open the file and read the data in list from list using lists.
(I use data from a string for clarity and read it as if from a file using StringIO .)
>>> from cStringIO import StringIO >>> data_file="1 2 3 4 5 6\n7 8 9 10 11 12\n13 14 15 16 17 18\n19 20 21 22 23 24\n" >>> reader=StringIO(data_file) >>> array=[map(int, reader.readline().split()) for i in xrange(4)] >>> array [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18], [19, 20, 21, 22, 23, 24]]
As the earlier answer is mentioned, numpy has a more direct method.
source share