close

[Solved] Python 3 – ValueError: not enough values to unpack (expected 3, got 2)

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Python 3 – ValueError: not enough values to unpack (expected 3, got 2) in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Python 3 – ValueError: not enough values to unpack (expected 3, got 2) Error Occurs?

Today I get the following error Python 3 – ValueError: not enough values to unpack (expected 3, got 2) in python.

How To Solve Python 3 – ValueError: not enough values to unpack (expected 3, got 2) Error ?

  1. How To Solve Python 3 – ValueError: not enough values to unpack (expected 3, got 2) Error ?

    To Solve Python 3 – ValueError: not enough values to unpack (expected 3, got 2) Error your program will still crash at the same place, because .items() still won't give you 3-tuples but rather something that has this structure: (name, (lastname, email))

  2. Python 3 – ValueError: not enough values to unpack (expected 3, got 2)

    To Solve Python 3 – ValueError: not enough values to unpack (expected 3, got 2) Error your program will still crash at the same place, because .items() still won't give you 3-tuples but rather something that has this structure: (name, (lastname, email))

Solution 1

You probably want to assign the lastname you are reading out here

lastname = sheet.cell(row=r, column=3).value

to something; currently the program just forgets it

you could do that two lines after, like so

unpaidMembers[name] = lastname, email

your program will still crash at the same place, because .items() still won’t give you 3-tuples but rather something that has this structure: (name, (lastname, email))

good news is, python can handle this

for name, (lastname, email) in unpaidMembers.items():

etc.

Solution 2

In this line:

for name, email, lastname in unpaidMembers.items():

unpaidMembers.items() must have only two values per iteration.

Here is a small example to illustrate the problem:

This will work:

for alpha, beta, delta in [("first", "second", "third")]:
    print("alpha:", alpha, "beta:", beta, "delta:", delta)

This will fail, and is what your code does:

for alpha, beta, delta in [("first", "second")]:
    print("alpha:", alpha, "beta:", beta, "delta:", delta)

In this last example, what value in the list is assigned to delta? Nothing, There aren’t enough values, and that is the problem.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read