Reading data from file: x(i),y(i) form

Satish Chimakurthi skchim0 at engr.uky.edu
Fri Feb 27 17:45:54 EST 2004


Hi all,

I have data of the following form in a file called "fluid_grid.dat"

  1.00000000000000        0.00000000000000D+000
  0.959753969508636       0.280842158538236
  0.842255363975169       0.539078752924891
  0.656961888321583       0.753923787456623
  0.418788196289889       0.908083942512068
  0.146905379223583       0.989150549489397

The first column gives values of x and the second, the values of y

My aim is to read the data into x(i), y(i) where i=1,6, and I wrote the following code for the purpose.

ifile4=open('fluid_grid.dat','r') 
lines=ifile4.readlines( )
x=[ ]
y=[ ]
i=1
for line in lines:
        x[i],y[i]=map(float,line.replace('D','E').split( ))
        i=i+1
        if i==7:
           break

I get the following error:

x[i],y[i]=map(float,line.replace('D','E').split( ))
Index Error: list index out of range


Can someone help me ?  Please let me know if there is a better way to serve my purpose.


Thanks

Regards,
Satish Kumar Chimakurthi


  
SATISH KUMAR CHIMAKURTHI
Graduate Research Assistant
CFD GROUP
Mechanical Engineering
UNIVERSITY OF KENTUCKY
Lexington
KENTUCKY - 40508
U.S.A

Email: skchim0 at engr.uky.edu
Mobile:859-420-9890
Office: 859-257-6336 X 80691
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040227/3be4d6ca/attachment.html>


More information about the Python-list mailing list