社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

自动更正python库抛出错误而不是更正单词

Blueberry Tech • 6 年前 • 2026 次点击  

我不确定为什么自动更正不起作用,但每次我尝试使用 Speller() 函数i得到此错误:

TypeError: '>' not supported between instances of 'str' and 'int'

这是我的代码:

import time
from autocorrect import Speller

def main(consoleMode):
    if consoleMode:
        # beg fur input :D
        inputVar = input("Console Mode input: ")
        if Speller(inputVar.lower()) == "hi" or Speller(inputVar.lower()) == "hello" or Speller(inputVar.lower()) == "wassup" or Speller(inputVar.lower()) == "sup":
            if name == None:
                name = int(input("Hello!\nI'd like to get to know you.\nWhat's your name?\n> "))
                if ("not" in Speller(name) and "tell" in Speller(name)) or ("not" in Speller(name) and "say" in Speller(name)):
                    print("Alright, I'll just call you Bob for now :)")
                    name = "Bob"
            else:
                print("Hey " + name + "!")
while True:
    main(True)

编辑:我也试过 int(disisastringvariable) 但它根本不起作用,因为它也会抛出一个错误

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52224
文章 [ 2 ]  |  最新文章 6 年前