Enchant是python中的一個模塊,用於檢查單詞的拚寫,並提供糾正單詞的建議。另外,給出單詞的反義詞和同義詞。它檢查字典中是否存在單詞。
enchant .Dict()
enchant.Dict()
是一種內置方法enchant
模塊。它用於創建Dict對象,這是該對象中最重要的對象。enchant
t模塊。 Dict對象表示特定語言的詞典。
用法: enchant.Dict(tag)
參數:
標簽:語言詞典的代碼(可選)
返回:Dict對象
範例1:
# import the enchant module
import enchant
# dictionary of en_US
d = enchant.Dict("en_US")
# the dictionary tag
tag = d.tag
print("The dictionary tag is " + tag)
The dictionary tag is en_US
範例2:當。。。的時候enchant.Dict()
方法在不傳遞任何參數的情況下執行,默認情況下它采用本地計算機語言的代碼。
# import the enchant module
import enchant
# instantiating the dictionary
# without passing any parameter
d = enchant.Dict()
# finding the dictionary tag
tag = d.tag
print("The dictionary tag is " + tag)
The dictionary tag is en_IN
範例3:的enchant.Dict()
如果沒有適當的字典,則該方法可能會失敗。在這種情況下,將顯示以下消息:
enchant.Dict()
輸出:
Traceback (most recent call last):
File “”, line 1, in
enchant.Dict()
File “C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\enchant\__init__.py”, line 541, in __init__
_EnchantObject.__init__(self)
File “C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\enchant\__init__.py”, line 144, in __init__
self._init_this()
File “C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\enchant\__init__.py”, line 548, in _init_this
this = self._broker._request_dict_data(self.tag)
File “C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\enchant\__init__.py”, line 286, in _request_dict_data
self._raise_error(e_str % (tag, ), DictNotFoundError)
File “C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\enchant\__init__.py”, line 233, in _raise_error
raise eclass(default)
enchant.errors.DictNotFoundError:Dictionary for language ‘English_India’ could not be found
相關用法
注:本文由純淨天空篩選整理自Yash_R大神的英文原創作品 enchant.Dict() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。