I'm doing ex13 from Learn Python The Hard Way
I'm trying to pass:
python ex13.py raw_input() raw_input() raw_input()
my code is below:
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
The error I keep getting is:
Traceback (most recent call last):
File "ex13.py", line 5, in <module>
script, first, second, third = argv
ValueError: too many values to unpack
I want to know why i'm getting this error and how to fix it
raw_input()
! The following works fine for me:python test.py 1 2 3
– Diepperaw_input()
it's not actually going to allow raw input. From the command line it's going to pass arg1, arg2 and arg3 from argv the stringraw_input
, arg0 will still remain the script name. However that should not throw an error since argv will produce values – Varroprint argv
and see what's there. That still won't solve the problem @ZWiki raised (command-line arguments are just strings, not code to be executed, so you're just going to get the string'raw_input()'
as the value offirst
, etc.—assuming your shell doesn't try to interpret that as a function call—bash
will, butcmd
won't, for example), but it will let you get past the exception so you can get to that problem, which is progress. – Tugboat