ValueError: not enough values to unpack
Error message
not enough values to unpack (expected 3, got 2)
Quick summary
You tried to unpack a sequence into a number of variables that doesn't match the sequence's length.
Why this happens
Unpacking a tuple/list with fewer elements than variables
Unpacking a string split result with the wrong number of parts
Expecting more return values than a function provides
Minimal example
data = (1, 2)
a, b, c = data # ValueError: not enough values to unpackdata = (1, 2)
a, b = data # Correct: 2 values, 2 variables
# Or use * for flexible unpacking:
# a, *rest = dataThe tuple has 2 elements but 3 variables were used. Match the variable count to the sequence length.
How to diagnose
Check the length of the sequence being unpacked
Verify the number of variables matches the sequence length
Print the sequence before unpacking to see its contents
How to fix
Match the number of variables to the sequence length
Use * to collect extra values: a, *rest = sequence
Check the length before unpacking
How to prevent
Verify sequence length before unpacking
Use * unpacking for variable-length sequences
Test with representative data