Python Forum

Full Version: ValueError: not enough values to unpack (expected 4, got 1)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
while trying to execute the program I got the error mention in the subject.
kindly help me in this, I am new to argv concept
from sys import argv

script, first, second, third = argv

print("The script is called:", script)
print("your first variable is", first)
print("your second variable is", second)
print("your third variable is", third)
Error:
script, first, second, third = argv ValueError: not enough values to unpack (expected 4, got 1)
you are expecting four arguments (including the script name, thus 3 additional) on the command where you call the script.
you are only getting the script name, thus the other three arguments haven't been supplied in your run command.
example (with your script named myscript.py):

$ python myscript.py opt1 opt2 opt3
Output:
The script is called: myscript.py your first variable is opt1 your second variable is opt2 your third variable is opt3
I would start with this:
from sys import argv
print(argv)
What gets printed? Try running your program with different command line arguments until you understand how argv works.