如何消除python cod中的语法问题

2024-04-29 00:06:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我用python编写了一个代码,并导入了所有需要的库。我解决了所有的错误,但我仍然得到一个语法错误

import enchant

from  nltk.metrics import edit_distance

class SpellingReplacer(object):

    def __init__(self, dict_name='en', max_dist=2):

     self.spell_dict = enchant.Dict(dict_name)

     self.max_dist = max_dist

     def replace(self, word):

      if self.spell_dict.check(word):
          return word
      suggestions = self.spell_dict.suggest(word)
    if suggestions and edit_distance(word, suggestions[0]):
       a=self.max_dist
    return suggestions[0]
    else:
        return word

在最后的第二行中,它给出了语法错误,即在(else:)语句中使用了无效语法。我是根据我的知识做的。另外,w3resource中的语法 和我的一样。我不知道怎么解决。请帮帮我


Tags: nameimportselfreturndistdefeditenchant