我不太确定如何让下面的代码在PyScripter中正常工作。
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 question."
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 the fuck that is!
And you have a %r computer. It's obviously a piece of shit!
""" % (likes, lives, computer)谢谢。
发布于 2014-12-10 18:40:09
当您将argv解压为2变量时,您需要在终端中传递user_name。
from sys import argv
script, user_name = argv
print user_name演示:
/Desktop$ python p.py userrrr
userrrr但是如果你不在运行时传递用户名,你会得到这个错误:
~/Desktop$ python p.py
Traceback (most recent call last):
File "p.py", line 51, in <module>
script, user_name = argv
ValueError: need more than 1 value to unpackhttps://stackoverflow.com/questions/27398496
复制相似问题