Common causes
- Unpacking a list/tuple with more items than target variables: a, b = [1, 2, 3]
- A function returned more values than expected
- Iterating over rows of data and the row has extra columns
- A CSV or split() result has more elements than you're unpacking into
How to fix it
- Add a starred variable to absorb the extra values: a, b, *rest = [1, 2, 3, 4]
- Or just access by index instead of unpacking: items = get_values(); a = items[0]
- Check what the function actually returns: print(get_values())
- Use only the values you need: a, b = values[:2]
Example
Traceback (most recent call last):
File "app.py", line 3, in <module>
x, y = get_coordinates()
ValueError: too many values to unpack (expected 2)Unpacking into two variables when get_coordinates() returns a tuple of three values
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
