how to read in an array in text file?

Ulrich Petri ulope at gmx.de
Sun Nov 9 12:17:39 CET 2003


"Yun Mao" <maoy at cis.upenn.edu> schrieb im Newsbeitrag
news:bokiea$bn00$1 at netnews.upenn.edu...
> Hi, what's the easy way of reading in a two-dimentional array from a text
> file?
> The text file looks like this:
> 0.1 1.1 2.3 12.1
> 0.3 33.0 4.1 1.1
>
> I'm using Numeric Python now. Other solutions are also welcome. Thanks a
> lot!
> Yun

f = file("myfile", "r")
data = [line.split() for line in f]
f.close()

HTH

Ciao Ulrich






More information about the Python-list mailing list