Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Error: "ValueError: need more than 1 value to unpack"

In Python, when I run this code:

from sys import argv  script, user_name =argv prompt = '>'  print "Hi %s, I'm the %s script." % (user_name, script) 

I get this error:

Traceback (most recent call last):   script, user_name =argv   ValueError: need more than 1 value to unpack 

What does that error mean?

like image 656
Captain Cretaceous Avatar asked May 11 '10 20:05

Captain Cretaceous


People also ask

How do you resolve ValueError too many values to unpack expected 2?

We can resolve the error by using a method called items() . The items() function returns a view object which contains both key-value pairs stored as tuples. Note: If you are using Python version 2. x, you need to use iteritems() instead of the items() function.

What does ValueError too many values to unpack expected 2 mean?

The ValueError: too many values to unpack (expected 2)” occurs when you do not unpack all of the items in a list. A common mistake is trying to unpack too many values into variables. We can solve this by ensuring the number of variables equals the number of items in the list to unpack.

What does ValueError not enough values to unpack expected 2 got 1 mean?

During a multiple value assignment, the ValueError: not enough values to unpack occurs when either you have fewer objects to assign than variables, or you have more variables than objects. This error caused by the mismatch between the number of values returned and the number of variables in the assignment statement.


1 Answers

Probably you didn't provide an argument on the command line. In that case, sys.argv only contains one value, but it would have to have two in order to provide values for both user_name and script.

like image 78
David Z Avatar answered Sep 23 '22 04:09

David Z