Py学习  »  Python

简单的Python文件I/O拼写检查程序

liam12808 • 5 年前 • 436 次点击  

<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
 
436 次点击  
文章 [ 2 ]  |  最新文章 5 年前