这里有什么问题? Python2 - > Python3

时间:2017-08-17 17:29:23

标签: python python-3.x iterable-unpacking

我正在使用名为Learn" Python The Hard Way 3rd edition"的书练习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)

我收到错误消息value error: not enough values to unpack (expected 4, got 1)

2 个答案:

答案 0 :(得分:2)

您需要使用三个参数运行脚本,以便argv包含四个元素(第一个是脚本的名称)。

答案 1 :(得分:1)

argv是一个包含以下内容的列表: argv [0]是脚本路径名(如果已知) argv [1],argv [2],argv [3] ...包含从shell传递的参数。

为了使你的代码能够工作,你需要使用3个参数运行它,这样它们就可以解压缩并分配给你的4个变量。

相关问题