On 12/08/2011 02: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?

I had a few errors sometimes because I thought I passed in a list while
I passed only a string, which since it's still iterable would just work
but explode later.

A nicer message wouldn't have really actually helped though, not sure
it's worth to make an exception for such a thing..
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to