ValueError: not enough values to unpack (expected 3, got 2)
What it means
You wrote several names on the left of =, like a, b, c = ..., but the value on the right had fewer items than names. The message gives both counts: how many names you wrote (expected) and how many items there were (got).
1. Text with fewer parts than you expected
This raises the error
Traceback (most recent call last): File "<exec>", line 2, in <module> ValueError: not enough values to unpack (expected 3, got 2)
The fix
18 10 2026
Checking len(parts) before unpacking lets you handle short values instead of crashing. Print the parts first when you are not sure what the text holds.
2. One line in the data is missing a field
This raises the error
Ana 90 Ben 85 Traceback (most recent call last): File "<exec>", line 3, in <module> ValueError: not enough values to unpack (expected 2, got 1)
The fix
Ana 90 Ben 85 skipping bad row: Cara
Real data often has a short or blank line. Checking the number of parts first lets you skip it or report it.
3. Unpacking more names than a function returns
This raises the error
Traceback (most recent call last): File "<exec>", line 4, in <module> ValueError: not enough values to unpack (expected 3, got 2)
The fix
4 8 6.0
A function returns exactly the values listed after return. Either unpack that many names or make the function return the extra value.
When you see this error, check
- Compare
expected(names on the left) withgot(items on the right). - Print the value, or its
len(), just before unpacking. - Check data for short or empty lines before splitting them into names.
str.partition()always returns three parts, so it is safe to unpack:key, _, value = line.partition('=').
Related errors
All Python errors · How to read a traceback · Step through your code