我运行以下代码:
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但是当我运行它的时候,我得到了这个错误:
ValueError: need more than 1 value to unpack
发布于 2015-12-17 06:12:43
script, first, second, third = argv将argv (必须包含4项)“解包”到相应的变量中。显然,您没有将这3个参数传递给您的脚本。
试着这样检查一下:
if len(argv) == 4:
script, first, second, third = argv
else:
print "Not enough arguments"发布于 2015-12-17 06:33:11
这意味着您没有为python脚本提供足够的参数。此错误意味着您尝试解压的值多于列表中的值。像python file.py a b c一样运行它。
尝试以下代码:
if len(argv) == 4:
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
else:
print "Not enough arguments"https://stackoverflow.com/questions/34323068
复制相似问题