2012-10-05 124 views
0
from sys import argv 

script, first, second, third = argv 

键入二号线后,我得到这个错误:python代码错误?

Traceback (most recent call last): File "", line 1, in ValueError: need more than 1 value to unpack

+1

''sys.argv''是命令行参数,如果是这样的解释器,它不会有三个参数。 –

回答

0

sys.argv isthe脚本的命令行参数。您的错误表明您尝试解压缩的变量数量超过了元组中的条目数量,即1。

您要么没有传递足够的参数,要么您正在运行命令来自口译员。

+0

我正在使用终端...我不应该使用它吗?我应该使用textwrangler吗?我是一名新程序员,非常感谢你的帮助。 –

+0

如果你从终端运行它,给你的脚本参数,如'python myscript.py a b c'。 – nneonneo

+0

终端很好(这就是我使用的)。你必须传递一些参数:'python script.py one two three'。 – Blender

0
from sys import argv 
a, b, c, d = argv 
print "The script is called:", a 
print "Your first variable is:", b 
print "Your second variable is:", c 
print "Your third variable is:", d 

保存此代码为:s.py

运行该文件从终端如下: enter image description here