下面代码Python3.x为什么运行失败啊!!!
from sys import argv
script,firdt,second,third=argv
print("The script is called:",script)
print("Your first variable is:",first)
print("Your second varoable is:",second)
print("Your third variable is:",third)
Up@牛牛不牛
9 years, 4 months ago
Answers
我尝试在IDLE交互模式下输入代码,当输入第二行代码时就直接报错了:ValueError: need more than 1 value to unpack.
但是我把代码全部打好后保存为.py文件(如unpack.py)再运行,在终端里输入~$ python3.4 unpack.py 1 2 3
可以正常打印出结果。
我也是初学,一起探讨一下。我想按照运行代码时解包需要输入4个参数,所以在交互模式下,前面4个参数(如:script,first,second,third = argv,1,2,3),后面就需要4个值一一对应。
另,你的第一个单词first打错了。
老衲来阅经啦
answered 9 years, 4 months ago
如果是在IED中运行会报错。需要在命令行下
保存为 test.py
python
from sys import argv print("The script is called:",argv[0]) print("The script is called:",argv[1]) print("The script is called:",argv[2]) print("The script is called:",argv[3])
然后
bash
python3 test.py I see you
输出
bash
he script is called: test.py The script is called: I The script is called: see The script is called: you
八云家的天子
answered 9 years, 4 months ago