在Valueerror需要大于1的地方出现错误

时间:2019-03-01 02:26:22

标签: python

在下面输入时

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

我在下面收到此错误:

Traceback (most recent call last):
  File "C:\python-files\ex13.py", line 3, in <module>
    script, first, second, third = argv
ValueError: need more than 1 value to unpack
>>> 

1 个答案:

答案 0 :(得分:0)

您正在尝试访问命令行参数,只有在您以这种方式调用脚本时才会发送这些参数:

python script.py first_argument second_argument third_argument

每个参数都用空格分隔。您收到的错误是因为您尝试访问参数,但没有传递参数。

尝试通过传递三个参数来调用脚本,它将被修复