python提示错误too many values to unpack
很多童鞋在参考“笨方法学习python"一书时遇到下面滴错误提示:
too many values to unpack
编写的代码如下,保存为文件名“ex13.py"
from sys import argv
#print 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 ex13.py
提示出错。
原因是argv需要调用需要带参数运行,采用如下运行方式即可正确输出:
python ex13.py 1 2 3
其中的1、2、3为运行参数,可以是任意字符,或者汉字,比如:
$ python ex13.py 1 2 我
the script is called: ex13.py
your first variable is: 1
your second variable is: 2
your third variable is: 我
操作方法
- 01
编织ex13.py后直接字命令行调用。
赞 (0)