problems when unpacking tuple ...

harold dadapapa at googlemail.com
Sat Apr 22 12:43:28 EDT 2006


Rene Pijlman schrieb:

> harold:
> >The output (when given the data I want to parse) is:
>
> If you'd told us that data, and told us what version of Python you're
> using, we could have reproduced the problem to look into it.
>

Thank you for the answers and sorry that I did not provide more
information in the first place.
My data file is white space seperated data (space seperated data to be
precise) and I am
using python 2.4.2


As can be seen, the output of the print statement in the lines

    except ValueError , err:
        print line.split()
        raise err

has exactly four values...


> >ValueError: need more than 3 values to unpack
> >
> >Why does python think that I want to unpack the outcome of
> >line.split() into three values instead of four?
>
> That's not what it says. It says there are only 3 values in the outcome,
> and it needs more (4 to be precise).


A similar error happens in an interpreter session, when typing
>>> for line in ["1 2 3 4"] :
...    for a,b,c,d in line.split() :
...        pass
...
Traceback (most recent call last):
  File "<stdin>", line 2, in ?
ValueError: need more than 1 value tyo unpack

maybe this might help to track down the error.
Thanks!

- harold -




More information about the Python-list mailing list