2 sinat 29379695 sinat_29379695 于 2016.05.10 23:39 提问

急!!!请教各位大神python报这个错怎么解?

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 s few questions.")
print("Do you like me %s?"%user_name)
likes = input(prompt)
print("Where do you like %s?"%user_name)
lives = input(prompt)
print("What kind of computer do you have?")
computer = input(prompt)
print("""
Alright,so you said %r about liking me.
You libe in %r.Not sure where that is.
And you have a %r computer.Nice.
""" %(likes,lives,computer))
报错:
Traceback (most recent call last):
File "ex14.py", line 3, in
script,user_name = argv
ValueError: not enough values to unpack (expected 2, got 1)

2个回答

Steval_Lee
Steval_Lee   2016.05.11 00:00
已采纳

错误不是说了吗 ,右一个两个参数,你只有一个,第一个参数是argc 第二个才是argv

sinat_29379695
sinat_29379695 回复sinat_29379695: script,user_name = argv,argv,改成这样可以正常运行,为什么?
一年多之前 回复
sinat_29379695
sinat_29379695 回复sinat_29379695: script,user_name = argv,argv
一年多之前 回复
sinat_29379695
sinat_29379695 请问具体怎么修改?(新手学编程,很多不懂,见笑)
一年多之前 回复
skipperrico
skipperrico   2017.01.25 13:54

这种情况需要在cmd端运行脚本,并给出参数。
将脚本保存为test.py,在cmd输入 python test.py user_name

Steval_Lee
Steval_Lee   2016.05.11 00:00

错误不是说了吗 ,右一个两个参数,你只有一个,第一个参数是argc 第二个才是argv

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!