Python错误:“ValueError:需要多于1个值才能解压缩”

时间:2015-12-20 01:13:41

标签: python pycharm

我正在尝试学习如何使用Python进行编码,每当我进行涉及from sys import argv的练习时,我都会收到此错误代码:

  

Traceback(最近一次调用最后一次):文件   “C:/ Users / Kaleb / PycharmProjects / python ex13.py”,第3行,in       script,first,second,third = argv 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

我不确定为什么会这样做,而且我对编码很新。我曾经环顾四周,但找不到任何有用的东西或我能理解的东西。

这个错误意味着什么,我需要做些什么来解决它?

1 个答案:

答案 0 :(得分:1)

您正在尝试将变量分配给不存在的值

script, first, second, third = argv

当您调用脚本时,您还需要传递三个参数

所以你可以这样调用你的脚本:

python ex13.py test1 test2 test3

您应该看到:

The script is called: ./ex13.py                                                                            
Your first variable is: test1                                                                               
Your second variable is: test2                                                                              
Your third variable is: test3
相关问题