我正在尝试对字符串列表进行拼写检查。使用下面的代码我只得到错误单词为(err.word)。但是,我想打印字符串以及错误字,如
"This is a msspelled string" : msspelled
我试过了
print("{} ".format(err.word), "{} ".format(chkr.get_text()))
但它没有产生我想要的东西。有什么建议吗?
from enchant.checker import SpellChecker
import pypyodbc as db
import pandas as pd
pd.set_option('max_rows', 10000) # overriding default number of rows
pd.set_option('display.max_colwidth', -1)
cnx = db.connect("DNS")
qry = ("""SQL""")
A = pd.read_sql(qry,cnx).to_string()
chkr = SpellChecker("en_US")
chkr.set_text(A)
for err in chkr:
print("{} ".format(err.word))
答案 0 :(得分:0)
这是你想要做的吗?
from enchant.checker import SpellChecker
A = "This iis a msspelled string"
chkr = SpellChecker("en_US")
chkr.set_text(A)
# Put all misspelled words in a list
misspelled_words = [err.word for err in chkr]
# Format and print this the sentence with the list of words.
print("{} : {}".format(A, ', '.join(misspelled_words)))