LOADING DATA INTO ARRAYS
Sorin Gherman
s_gherman at yahoo.com
Wed Jul 9 16:15:52 EDT 2003
It's easy, split returns a 3-elements list in your case, while you try
to read that with just 2 elements, xval, yval.
Will work like this:
xval,yval,zval = string.split(line)
/sorin
> Hi,
>
> I am trying to collect the following data in X,Y,Z arrays as following:
>
> 1.00000000000000 0.00000000000000D+000 0.00000000000000D+000
> 0.932113519778473 0.362166241174114 0.00000000000000D+000
> 0.737671227507627 0.675160099611485 0.00000000000000D+000
> 0.443073128844408 0.896485472551578 0.00000000000000D+000
> 8.83176797852179D-002 0.996092358889152 0.00000000000000D+000
> -0.145819420809848 0.989311223283493 0.00000000000000D+000
> -0.391263558087552 0.920278668726310 0.00000000000000D+000
> -0.625821331717327 0.779966448488364 0.00000000000000D+000
> -0.822296905793933 0.569058695322129 0.00000000000000D+000
> -0.953713306870443 0.300717356163965 0.00000000000000D+000
>
> After loading them into X,Y,Z arrays, I should be in a position to access the
> first line as X[0],Y[0], Z[0] and second line stuff as X[1],Y[1],Z[1].
>
> I have written the following code which is not working for some reason. Can
> anyone suggest any changes:
>
> ifile1 = open('fluidcylinder', 'r') #fluidcylinder contains the above data
> for line in ifile1:
> xval,yval=string.split(line)
> x.append(xval)
> y.append(yval)
>
> The error I am getting after the compilation is as follows:
>
> xval,yval=string.split(line)
> ValueError: unpack list of wrong size
>
>
> I would really appreciate if someone can help me with this.
>
> Thanks in advance,
>
> SATISH
>
>
>
>
>
More information about the Python-list
mailing list