python - 类型错误 : 'str' object is not callable

标签 python

我正在尝试运行下面的简单代码:

from sys import argv
script, filename = argv
print ("erase %r") % filename
raw_input = ("?")
target = open(filename, 'w')
print ("truncate")
target.truncate()
print ("fline")
repeat3 = raw_input ('> ')
print ("write")
target.write(repeat3)

我不断收到错误:

Traceback (most recent call last):
  File "ex9.py", line 9, in <module>
    repeat3 = raw_input ('> ')
TypeError: 'str' object is not callable

最佳答案

当你这样做的时候:

raw_input = ("?")

您已将名称 raw_input 分配给字符串 "?",因此您无法再调用该函数(相反,您正在调用字符串,它不会不工作)。

为您的变量使用不同的名称(虽然看起来您甚至没有使用它,因此您可以简单地删除有问题的行)。

关于python - 类型错误 : 'str' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31145541/

相关文章:

python - 远程图像上传的执行方式与开发服务器不同

python - 多种可能的输入

python - 查找两个字符串的接触部分和非接触部分

python - 交互运行 pyprocessing 脚本时出现 TypeError : super(type, obj)

python - 处理移动平均线中的零

python - 如何从 grafana V 2.0 仪表板中的图表中获取值

python - 尝试在 for 循环之外使用变量会出现 SyntaxError : no binding for nonlocal 'max_' found

python - 最小化相互不相交的二分对之间的距离总和

python - 属性错误: 'Flask' object has no attribute 'login_manager' -- Login_Manager

python - 在 python 上,如何在加入 float 列表后去掉引号?