LOADING DATA INTO ARRAYS

Skip Montanaro skip at pobox.com
Wed Jul 9 14:02:53 EDT 2003


    satish>  I am trying to collect the following data in X,Y,Z arrays as
    satish>  following:
    
    satish>   1.00000000000000        0.00000000000000D+000   0.00000000000000D+000
    satish>   0.932113519778473       0.362166241174114        0.00000000000000D+000
    satish>   0.737671227507627       0.675160099611485        0.00000000000000D+000
    ...

    satish> The error I am getting after the compilation is as follows:

    satish>  xval,yval=string.split(line)
    satish> ValueError: unpack list of wrong size

That's because the string.split() operation yields a list containing three
values per line, not two, and you're trying to assign those three values to
only two variables.  If you don't want the third field you can discard it a
couple ways:

    # only assign the first two items
    xval,yval=string.split(line)[0:2]

or

    # assign the third item to a dummy variable
    xval,yval,dummy=string.split(line)

Skip





More information about the Python-list mailing list