首页 > 解决方案 > 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

解决方案


推荐阅读