Not sure how to use argv with Spyder
I am running the code below in Spyder. I typed it in the py file and just hit the start button.
When I try to run it, I get an error:
ValueError: More than 1 value required to unpack
As shown here, you have to specify the inputs for the argv variable before running the program, but I don't know how to do that, is it spyder?
http://learnpythonthehardway.org/book/ex13.html
from sys import argv
script, first, second, third = argv
print "The script is called:", script
print "The first variable is:", first
print "The second variable is:", second
print "Your third variable is:", third
source to share
Read the FAQ at the bottom of the page, it specifically mentions this error.
General questions for students
Q. When I run it, I get
ValueError: need more than 1 value to unpack
.Remember, an important skill is attention to detail. If you look at the What you should see section, you can see that I am running the script with parameters on the command line. You should replicate how I did it exactly.
Make sure you run the command:
$ python ex13.py first 2nd 3rd
>> The script is called: ex13.py
>> Your first variable is: first
>> Your second variable is: 2nd
>> Your third variable is: 3rd
You can guarantee that arguments will be provided.
if __name__ == '__main__':
if len(argv) == 4:
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
else:
print 'You forgot the args...'
source to share
To pass argv
to script in Spyder you need to go to the menu item
Run > Configuration per file
or press the key Ctrl+F6, then look for the option named
Command line options
in the dialog that appears after that and finally enter the command line arguments you want to pass to the script, which in this case could be
one two three
source to share