0

我正在尝试对字符串列表进行拼写检查。使用下面的代码,我只得到错误词(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))
4

1 回答 1

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)))
于 2018-05-03T10:52:59.477 回答