Misleading error message of the day
Roy Smith
roy at panix.com
Thu Dec 8 10:42:46 EST 2011
More information about the Python-list mailing list
Thu Dec 8 10:42:46 EST 2011
- Previous message (by thread): Misleading error message of the day
- Next message (by thread): Misleading error message of the day
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thursday, December 8, 2011 10:16:56 AM UTC-5, Heiko Wundram wrote:
> Am 08.12.2011 15:47, schrieb Robert Kern:
> > Would including the respective numbers help your thought processes?
> > ValueError: too many values to unpack (expected 2, got 3)
>
> Not possible in the general case (as the right-hand side might be an
> arbitrary iterable/iterator...).
Why not? Take this example:
def i():
i = 0
while True:
print "returning:", i
yield i
i += 1
a, b = i()
./iter.py
returning: 0
returning: 1
returning: 2
Traceback (most recent call last):
File "./iter.py", line 10, in <module>
a, b = i()
ValueError: too many values to unpack
The exception was raised when i() returned it's third value, so saying "expected 2, got 3" is exactly correct. Yes, it is true that it might have gotten more if it kept going, but that's immaterial; the fact that it got to 3 is what caused the Holy Hand Grenade to be thrown.
- Previous message (by thread): Misleading error message of the day
- Next message (by thread): Misleading error message of the day
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list