Reading data in lists: Error

Satish Chimakurthi skchim0 at engr.uky.edu
Fri Feb 27 20:34:14 EST 2004


Hi all,


This is in continuation of my email today regarding reading data files. I am stuck with one more problem now. 

Here are my two data files:

a. 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

b. fluid_pressure.dat

 1.2
  2
  4
  5
  3.22       
  
There are six values in each of the two columns in file "fluid_grid.dat" and 6 values in one column in "fluid_pressure.dat".

I read the contents of the first file in two arrays "x" and "y", x contains the values in the first column and y contains the second column values respectively.

I also read the contents of the second file in array "pres"

I wrote the following code for some calculations. 

from math import sqrt
ifile4=open('fluid_grid.dat','r')
lines=ifile4.readlines()
x=[]
y=[]
FX=[]
FY=[]
for line in lines:
        xi,yi=[float(item) for item in line.replace('D','E').split()]
        x.append(xi)
        y.append(yi)

pres=[]
pressure_data=open('fluid_pressure.dat','r')


for i in range(1,6):
        a=eval(pressure_data.readline())
pres.append(a)

for i in range(1,6):
        NXA=y[i-1]-y[i]
        NXD=sqrt(((y[i]-y[i-1])**2)+((x[i]-x[i-1]**2))
        NYA=x[i]-x[i-1]
        NYD=sqrt(((y[i]-y[i-1])**2)+((x[i]-x[i-1]**2))
        NX=NXA/NXD
        NY=NYA/NYD
        FX.append(pres[i]*NX)
        FY.append(pres[i]*NY)


I ran this code only to get the following error:

 File "<string>", line 24
    NYA=x[i]-x[i-1]
      ^
SyntaxError: invalid syntax


I remember Mr.Skip Montanaro quoting in his email earlier that at the point I make the assignment neither x has no 
i'th elements. I am sure this is what is happening now.


Can someone advise any possible work around to this problem ??



Thanks in advance

Best 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/35ff6afe/attachment.html>


More information about the Python-list mailing list