On 26 Jan 2005 20:53:02 -0800, mcg <[EMAIL PROTECTED]> wrote:
> Investigating python day 1:
>
> Data in file:
> x y
> 1 2
> 3 4
> 5 6
>
> Want to read file into an array of pairs.
>
> in c: scanf("%d %d",&x,&y)---store x y in array, loop.
>
> How do I do this in python??
> In the actual application, the pairs are floating pt i.e. -1.003
f = file('input', 'r')
labels = f.readline() # consume the first line of the file.
Easy Option:
for line in f.readlines():
x, y = line.split()
x = float(x)
y = float(y)
Or, more concisely:
for line in f.readlines():
x, y = map(float, line.split())
Regards,
Stephen Thorne
--
http://mail.python.org/mailman/listinfo/python-list