2

我正在关注 zed shaw 的 learn python hard way 并且正在关注练习 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.

现在,我不确定问题出在哪里。唯一的原因可能是我正在输入文件路径而不是仅输入文件名。

4

1 回答 1

3

该脚本期望在命令行中接受一个参数。你不提供一个。

在终端中,键入python e:\python\ex14.py YourNameHere

于 2012-04-07T14:00:44.547 回答