我正在尝试运行下面的简单代码:
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/