0

我正在学习 learnpythonthehardway.org 的练习 13。我应该运行这段代码:

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

然后在命令行输入“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 

但是,我在 Vista 上使用 Aptana Studio 3 时出现“ValueError: too many values to unpack”错误。

我是 Python 和 Aptana 的新手,所以如何在此处输入单独的参数?

4

2 回答 2

1

这是因为len(argv)可能大于 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

尝试打印argv以查看argv实际包含的内容。

于 2012-09-25T03:38:19.870 回答
0

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.

于 2013-12-14T05:45:18.293 回答