Python Forum

Full Version: import argv
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

I am trying to work through the text book 'Learn Python the hard way' and I am getting stuck on Exercise 13:

from sys import argv

script, first, second, third = argv

program = input("What program do you use? ")

print("The script is called:", script)
print("Your first variable is:", first)
print("Your second variable is:", second, f"{program}")
print("Your third variable is:", third) 
ValueError: not enough values to unpack (expected 4, got 3)

He explains this issue happens when you don't put enough arguments on the command when you run it. However I am not sure what he means because I copied his code exactly. Also he mentions reading WYSS section but I am note sure what that is, any ideas?

I am trying to run this in jupyter notebook
What the problem just to look into argv with print function?
print(argv)
(Nov-11-2019, 07:21 AM)Scott Wrote: [ -> ]I am trying to run this in jupyter notebook
That's the problem,argv is a way to get arguments from command line passed to the script.
So i think you use Windows then it would be cmd or cmder as i use.
C:\code
λ python argv_test.py a b c
What program do you use? cmder
The script is called: argv_test.py
Your first variable is: a
Your second variable is: b cmder
Your third variable is: c

argv is the simplest way,but have limitation if writing more than simple stuff.
argparse is in standard library,i like Click if writing more than simple stuff for use from command line.
You must be passing less than 4 arguments. The error says, 4 variables are expected but only 3 were given by you.
py ex13.py first 2nd 3rd, this is how it should work.
"ex13.py" = 1st variable (script)
"first" = 2nd variable (first)
"2nd" = 3rd variable (second)
"3rd" = 4th variable (third)

AND WYSS sections refers to "What You Should See" section, which is just below the code.