首页 > 解决方案 > 在 Valueerror 需要大于 1 的地方出现错误

问题描述

当在下面输入

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
>>> 

标签: python

解决方案


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

python script.py first_argument second_argument third_argument

每个参数都用空格隔开。你得到的错误是因为你试图访问参数但你没有传递它们。

尝试调用传递三个参数的脚本,它将得到修复


推荐阅读