1
Traceback (most recent call last):
    File "filter_import.py", line 77, in <module>
        get(sys.argv[1])
    File "filter_import.py", line 35, in get
        timestamp, ip, hash_value = lines.split()
ValueError: need more than 2 values to unpack

I got this error message when I run my code filter_import, can anyone explain a bit what the problem is?

Part of my code:

if __name__ == '__main__':
import sys
if len(sys.argv) == 1:
    print 'Usage: filter_import.py <filename>'
    sys.exit(1)
get(sys.argv[1])

1 Answer 1

6

The line in question doesn't provide two values, so the "unpacking" of split()'s return value into the two variables timestamp, ip and hash_value is failing.

Here's a stand-alone reproduction of the error:

>>> a,b,c = "foo".split()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: need more than 1 value to unpack
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, but what about this part? File "filter_import.py", line 77, in <module> get(sys.argv[1]), is there anything wrong as well? @unwind
No. This a part of the stack trace. The stack trace shows you the lines of code the interpreter went through to get to the line of code raising the exception. In your example it just indicates that method get has been called from line 77 of your module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.