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"的代码,但它没有运行,我不知道为什么。
产生的错误如下:
Traceback (most recent call last):
File "E:/python/untitled1/new.py", line 6, in <module>
script, first, second, third, = argv
ValueError: need more than 1 value to unpack
答案 0 :(得分:1)
您需要确保在脚本运行时传递给脚本的参数大于1.在终端中,您的脚本会抛出错误:
$ python ./script.py
但这不会
$ python ./script.py arg1 arg2 arg3
由于您正在使用PyCharm,因此您需要执行'Before launch/show this page'并在那里进行编辑。