python
value_error
ai_generated
true
ValueError: too many values to unpack (expected 2)
ID: python/valueerror-too-many-values-unpack
92%Fix Rate
93%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 311 | active | — | — | — |
Root Cause
Unpacking assignment count mismatch. Common with CSV, split(), and tuple returns.
genericWorkarounds
-
92% success Check actual length of data; use *rest for variable-length unpacking
first, *rest = line.split(',')Sources: https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences
-
88% success Validate data format before unpacking
parts = line.split(',') if len(parts) != 3: raise ValueError(f'Expected 3 columns, got {len(parts)}: {line!r}') name, age, email = parts
Dead Ends
Common approaches that don't work:
-
Pad or truncate the iterable
70% fail
Silently drops or fabricates data
-
Catch ValueError and skip the row
60% fail
Loses data without understanding why
Error Chain
Frequently confused with: