1

我正在编写一个使用 raw_input 的简单命令行脚本,但它似乎不起作用。

这段代码:

print "Hello!"
raw_input("")

产生此错误:

Traceback (most recent call last):
 File "<pyshell#6>", line 1, in <module>
raw_input("")
TypeError: 'str' object is not callable

我以前从未遇到过此错误,并且在 Google 上找不到任何内容。我在 Windows 7 上使用 Python 2.6。

4

2 回答 2

2

工作正常,例如在任何 Python 2 版本的解释器提示中:

>>> print "Hello!"
Hello!
>>> raw_input("")
bah
'bah'
>>> 

bah我在您为响应空提示而提供的代码之后键入的内容在哪里;-)。

您提到的错误的唯一解释是您在此之前执行了其他代码,其中包括将标识符绑定raw_input到字符串。

于 2010-09-01T05:24:31.720 回答
2

看来您正在使用名为pyshell. 该外壳本身可能存在错误。尝试只使用香草 bash。

于 2010-09-01T05:26:34.680 回答