Search code examples
pythonerror-handlingvariable-assignmentiterable-unpacking

finding the missing value for ValueError: need more than X values to unpack


I have a function call that looks like this:

a,b,c,x,y,z = generatevalues(q)

Its in a try block to catch the error but I also need to find out which value is missing. I can't clear the variables beforehand either. I'd also rather not merge the 6 variables inside the function into a list and pass it, but other than that is there a way of finding out which variable(s) are missing?


Solution

  • values = tuple(generatevalues(q))
    try:
        a, b, c, x, y, z = values
    except ValueError as e:
        print(len(values)) # for example
        print(values)
    

    To debug this function - it's a good time to learn about the debugger

    values = tuple(generatevalues(q))
    try:
        a, b, c, x, y, z = values
    except ValueError as e:
        import pdb; pdb.set_trace()