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?
string are iterable, considering this, the error is correct.

Values to unpack in 'foo' are 'f', 'o', 'o'

> a,b,c = 'foo'

> print a,b,c
f o o


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

Reply via email to