社区所有版块导航
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
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Simon Crane

Simon Crane 最近创建的主题
Simon Crane 最近回复了
6 年前
回复了 Simon Crane 创建的主题 » 自动更正python库抛出错误而不是更正单词

您正在尝试将要检查的代码传递给 Speller 构造器。
相反,您应该创建一次对象,然后它是可调用的并检查输入。请阅读以下示例: https://github.com/fsondej/autocorrect

import time
from autocorrect import Speller

my_speller = Speller(lang='en')
name = None

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

while True:
    main(True)

变量也有问题 name 在声明之前使用-我认为您希望有这个的全局实例,并在对主函数的所有调用中使用它。

7 年前
回复了 Simon Crane 创建的主题 » python使用正则表达式拆分字符串
a, b = re.match('"(.*)"(.*)', bobbles).groups()

括号确定“保存”到匹配对象的组

7 年前
回复了 Simon Crane 创建的主题 » python 3.7:为什么不能将值插入到列表中?

你不需要经历所有的事情,而且 split 已返回列表

with open(name + ".txt", "r") as file:
    lines = file.readlines()
    new_currLanguage  = lines[0].split(" - ")
    firstLanguage = new_currLanguage[0]
    secondLanguage = new_currLanguage[1]