【发布时间】:2019-05-04 22:01:31
【问题描述】:
对于一个班级,我必须创建一个简单的拼写检查程序,该程序接受两个文件作为输入,一个包含正确拼写的单词,一个包含一个包含一些拼写错误单词的段落。我以为我已经弄清楚了,但我遇到了一个我以前从未见过的错误。当程序完成时,它会给出错误:
<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-3.x string file-io text-files spell-checking