Python 如何更正解包脚本中的TypeError

Python 如何更正解包脚本中的TypeError,python,typeerror,argv,Python,Typeerror,Argv,我正在学习编写Python2代码,并使用LearnPython建立了一个经过验证的工作脚本,在这里我解包了一个参数变量。代码如下: from sys import argv script, username = argv prompt = '> ' print "Hi %s, I'm the &s script." % (username, script) 我希望代码可以打印: Hi Zed, I'm the ex.py14 script. 相反,这是输出: Traceb

我正在学习编写Python2代码,并使用LearnPython建立了一个经过验证的工作脚本,在这里我解包了一个参数变量。代码如下:

from sys import argv

script, username = argv

prompt = '> '

print "Hi %s, I'm the &s script." % (username, script)
我希望代码可以打印:

Hi Zed, I'm the ex.py14 script.
相反,这是输出:

Traceback (most recent call last):
  File "ex14.py", line 6, in <module>
    print "Hi %s, I'm the &s script." % (username, script)
TypeError: not all arguments converted during string formatting
%s而不是&s

from sys import argv

script, username = argv

prompt = '> '

# %s instead of &s
print "Hi %s, I'm the %s script." % (username, script)
在打印语句中将&s更改为%s,请检查代码。设置字符串格式时出错

from sys import argv

script, username = argv

prompt = '> '

print "Hi %s, I'm the &s script." % (username, script)

&s应该是%s。投票以打字错误结束。请在“打印嗨%s,我是&s脚本”中将&s替换为%s。%用户名,脚本',应该可以。哇,我没有看到,谢谢,我会要求关闭它