学习python的错误是艰苦的练习14

时间:2012-04-07 13:57:46

标签: python

我正在跟着zed shaw学习python,并且正在进行练习14.以下是我正在讨论的程序:

from sys import argv

script, user_name = argv
prompt = '> '

print "Hi %s, I'm the %s script." % (user_name, script)
print "I'd like to ask you a few questions."
print "Do you like me %s?" % user_name
likes = raw_input(prompt)

print "Where do you live %s?" % user_name
lives = raw_input(prompt)

print "What kind of computer do you have?"
computer = raw_input(prompt)

print """
Alright, so you said %r about liking me.
You live in %r.  Not sure where that is.
And you have a %r computer.  Nice.
""" % (likes, lives, computer)

现在,我使用命令

在powershell终端中运行此程序
python e:\python\ex14.py

我收到以下错误消息:

Traceback (most recent call last):
File "e:\python\ex14.py", line 3, in (module)
script, user_name=argv
ValueError: need more than 1 value to unpack.

现在,我不确定问题是什么。唯一的原因可能是我正在键入文件路径而不是仅键入文件名。

1 个答案:

答案 0 :(得分:3)

此脚本希望在命令行中使用参数。你没有提供。

在终端上,输入python e:\python\ex14.py YourNameHere