python - TypeError:“str”对象不可调用。处理输入()
问题描述
为什么我会收到此错误,我该如何解决?
import json
from difflib import SequenceMatcher
from difflib import get_close_matches
data = json.load(open("data.json"))
def translate(word):
match = get_close_matches(word,data.keys(),cutoff=0.8)
if word.lower() in data:
return data[word.lower()]
elif len(match) > 1:
yn = input("Did you mean %s? Enter y or n" %match[0])
else:
return "Not in the dictionary. Please check again."
input = input("What is your word? ")
print(translate(input))`
What is your word? caca
Traceback (most recent call last):
File "dictionary.py", line 18, in <module>
print(translate(input))
File "dictionary.py", line 12, in translate
yn = input("Did you mean %s? Enter y or n" %match[0])
TypeError: 'str' object is not callable
解决方案
推荐阅读
- python - 如何根据文件名组合/附加PDF?
- php - 即使为空,数组也充满了空白值
- mysql - eZ平台本地安装无法连接MySQL数据库
- amazon-s3 - Cloud Storage 客户访问最佳做法
- amazon-web-services - AWS 节点的 Docker 上是否有时间同步过程?
- python - pdoc 生成的 HTML 中的方法参数格式不正确
- go - 如何在 EC2 实例的 2 个端口上运行简单的 Go 服务器?
- ios - 多个命令在存档上产生 gRPCCertificates.bundle 错误(iOS Xcode 11.1,Firebase SDK)
- c# - 无法访问 C# 中 Activator 返回的对象方法
- swift - 如何在 Swift 中转换 @Binding