fuckingpython.lol

Python errors › ValueError

ValueError: not enough values to unpack

Updated

The Python error "not enough values to unpack (expected 2, got 1)": the right side has fewer items than names on the left, usually a split with no separator.

What you see

main.py
lines = ["ada,ada@example.com", "grace"]

for line in lines:
    name, email = line.split(",")
    print(name, email)
Python 3.15 prints
Traceback (most recent call last):
  File "/home/me/project/main.py", line 4, in <module>
    name, email = line.split(",")
    ^^^^^^^^^^^
ValueError: not enough values to unpack (expected 2, got 1)

ada ada@example.com

What it means

name, email = … needs exactly two items on the right. The second line has no comma, so split(",") returns a list of one item, ["grace"], and there is nothing for email.

The message gives both counts: "expected 2" is the number of names on the left, "got 1" the number of items that came.

Why it happens

  • A separator that is missing from some lines, as in the example.
  • A blank line, often the last one of a file: "".split(",") gives [""], one item.
  • A function that returns fewer values on some path, such as one value on success and two on failure.
  • Short rows in a CSV file or a list of tuples.

How to fix it

Skip lines that are blank, and check the shape before unpacking:

for line in lines:
    if not line.strip():
        continue
    parts = line.split(",")
    if len(parts) != 2:
        print("skipping", repr(line))
        continue
    name, email = parts

str.partition() always returns three items, so it never fails to unpack; a missing separator gives empty strings:

name, _, email = line.partition(",")   # "grace" gives ("grace", "", "")

How each Python version words it

PythonPrints
3.9–3.15ValueError: not enough values to unpack (expected 2, got 1)

Run on CPython 3.9.6, 3.10.22, 3.11.17, 3.12.15, 3.13.17, 3.14.9 and 3.15.1, on October 25, 2026.

The wording is the same in every version here.

Questions

Why "got 1" when the line was empty?

Splitting an empty string on a separator returns a list with one empty string, [""]. Calling split() with no argument is different: "".split() returns [], and the message says "got 0".

Can I give a default for the missing value?

Not in the unpacking itself. Pad the list first, for example name, email = (line.split(",") + [""])[:2], or use partition() as above.

Sources

Read on October 25, 2026.