【发布时间】:2017-07-19 09:47:00
【问题描述】:
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 3) 代码时,我得到了
类型错误“%:'Nonetype' 和 'str' 的操作数类型不受支持”
这里有什么错误?
【问题讨论】:
-
未来:请同时发布您看到的错误的完整堆栈跟踪。否则我们只需要猜测错误发生在哪里。如果你自己看,你可能已经看到错误出现在
print调用的行上,因此它与argv或任何东西无关。 -
这段代码好像很破。你用的是python3吗?但是不要使用打印功能(带括号),您使用
raw_input。你确定它不是py2吗? -
@PaulRooney 修复问题中的错误后,OP 可能会看到
NameError用于raw_input。 -
你 not 在 Python 3 中运行 this 脚本。它会抛出
SyntaxError。请重新检查您问题中的代码是否与您实际运行的代码匹配并产生同样的问题。
标签: python python-3.x python-3.6