0
ValueError: not enough value to unpack
hi 1 from says import argv 2 3 script, first, second, third = argv 4 5 print("the script is called:", script) 6 print("your first variable is:", first) 7 print("your second variable is:", second) 8 print("your third variable is:", third) when I run it I get this: ... line 3, in <module> ...script, first, second, third = argv ValueError: not enough values to unpack ( expected 4, got 1)
1 Antwort
+ 9
argv is an arguments vector (list) containing arguments passed when running a program from command line
if you would simply do print(argv) you will see a file name.
that's because the first argument is always the program's name
in your example, as i suspect the progarm did not ran from command line, so there weren't any additional arguments passed on
look at the example in the following link:
https://www.daniweb.com/programming/software-development/threads/401173/interpret-from-sys-import-argv-into-english-please
from that page, in the example:
~~~~~~
from sys import argv
print(argv[0])
print(argv[1])
print(argv[2])
print(argv[3])
command line call:
test.py david 8 jenny
output:
>>> test.py
david
8
jenny
~~~~~~~
if you were to run the same script you supplied, there would be no issues, as the command line call supplies 3 additional arguments, making it a total of 4
TL;DR
argv is an argument list and in your example it did not have enough arguments, which caused the error as the program tried to unpack a list with 1 element into 4 seperate objects