-1

I am facing a problem with the following error message in python.

ValueError: not enough values to unpack (expected at least 2, got 1)

a code line with the above error is

op, param, *val = statement.split()

I tried to find where a line has only one at least not 2 using print value. But there are so many lines so I can't find it.

Do you know how to find a line with the problem easier?

wjandrea
  • 28,235
  • 9
  • 60
  • 81
KC Lee
  • 7
  • 2
  • The error would have included, in the console, a stack trace that shows you where exactly that code is (it starts with `Traceback (most recent call last):`). If the `statement.split()` part isn't in code you've written, you're likely passing the wrong arguments to a library function somewhere. The stack trace will show you exactly where. – Carcigenicate Oct 24 '19 at 00:26

2 Answers2

0

One simple way to do this is to catch the error, print the value, then raise the error again

try:
    op, param, *val = statement.split()
except ValueError:
    print(repr(statement))
    raise
wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • Related: [Python try/except: Showing the cause of the error after displaying my variables](https://stackoverflow.com/q/4560288/4518341) – wjandrea Oct 24 '19 at 01:05
0

or you can just print all the statements and some other information like the length of the list and maybe the split list also.. its easier to know exactly what is wrong.

print(statement)
l = statement.split()
print(l)
print("len : ", len(l))
op, param, *val = l
Eshaka
  • 974
  • 1
  • 14
  • 38