2012-10-05 126 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