问题
I am working on exercise 13 from learnpythonthehardway.org. I should run this code:
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
Then enter "python ex13.py first 2nd 3rd" on command line and should output:
The script is called: ex13.py
Your first variable is: first
Your second variable is: 2nd
Your third variable is: 3rd
However, I am using Aptana Studio 3 on Vista and I get the "ValueError: too many values to unpack" error.
I am new to Python and Aptana so how can I enter the separate arguments here?
回答1:
It's because len(argv)
might be greater than 4:
>>> w,x,y,z=[1,2,3,4,5]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: too many values to unpack
Try printing argv
to see what argv
actually contains.
回答2:
in the script window, right click, ShowIn > Terminal. It will open a terminal window in Aptana. Then type, python 'your script'.py That will run in way you want I think; Rather with the visual you want.
来源:https://stackoverflow.com/questions/12575870/valueerror-too-many-values-to-unpack-aptana-studio-3