LOADING DATA INTO ARRAYS

Jiri Barton jbar at lf1.cuni.cz
Thu Jul 10 08:02:34 EDT 2003


Solution:
---------

ifile1 = open('fluidcylinder', 'r')  #fluidcylinder contains the above
for line in ifile1:
  xval,yval,zval = filter(None, line.split())
  x.append(xval)
  y.append(yval)
  z.append(zval)


Because if the line is '123   456 789', then line.split() is
['123', '', '', '456', '789']
This means it will split every string between every space in the string. The
split() function thinks the original string is
123-space-empty-space-empty-space-456-789.

The error, unpack of wrong size means you wanted to assign 
xval,yval,zval = ('123', '', '', '456', '789')
.....3-tuple ? 5-tuple

The solution just filters out the members of the list that are false (the
None is the identity function) = effectively filtering out the empty
strings.



HTH,  Jiri




More information about the Python-list mailing list