On 12/8/11 2:23 PM, Roy Smith wrote:
I just spent a while beating my head against this one.

# Python 2.6
a, b = 'foo'
Traceback (most recent call last):
   File "<stdin>", line 1, in<module>
ValueError: too many values to unpack

The real problem is that there's too *few* values to unpack!  It should
have been

a, b = 'foo', 'bar'

I understand why it's generating the exception it does (the string is an
iterable), but man, did that message throw off my thought processes and
lead me down some totally bogus debugging paths.

It's an unusual case to want to unpack a string.  Maybe the message
should changed to "too {many, few} values to unpack (are you sure you
wanted to unpack a string?)" if the RHS is a basestring?

Would including the respective numbers help your thought processes?

ValueError: too many values to unpack (expected 2, got 3)

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to