社区所有版块导航
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文件I/O拼写检查程序

liam12808 • 5 年前 • 431 次点击  

<function check_words at 0x7f99ba6c60d0>

我从来没有见过,也不知道这意味着什么,任何帮助使这个计划工作将不胜感激。程序代码如下:

import os
def main():
    while True:
        dpath = input("Please enter the path to your dictionary:")
        fpath = input("Please enter the path to the file to spell check:")
        d = os.path.isfile(dpath)
        f = os.path.isfile(fpath)

        if d == True and f == True:
            check_words(dpath, fpath)
            break

    print("The following words were misspelled:")
    print(check_words)

def linecheck(word, dlist):
    if word in dlist:
        return None
    else:
        return word

def check_words(dictionary, file_to_check):
    d = dictionary
    f = file_to_check
    dlist = {}  
    wrong = []  


    with open(d, 'r') as c:
        for line in c:
            (key) = line.strip()
            dlist[key] = ''

    with open(f, 'r') as i:
        for line in i:
            line = line.strip()
            fun = linecheck(line, dlist)
            if fun is not None:
                wrong.append(fun)

    return wrong

if __name__ == '__main__':
    main()
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/56510
 
431 次点击  
文章 [ 2 ]  |  最新文章 5 年前