Enchant是python中的一個模塊,用於檢查單詞的拚寫,並提供糾正單詞的建議。另外,給出單詞的反義詞和同義詞。它檢查字典中是否存在單詞。
enchant .request_dict()
enchant.request_dict()
是一種內置方法enchant
模塊。它用於獲取特定語言的字典對象。
用法: enchant.request_dict(tag)
參數:
標簽:語言代碼
返回:Dict對象
範例1:
# import the enchant module
import enchant
# dictionary of en_US
d = enchant.request_dict("en_US")
# the dictionary tag
tag = d.tag
print("The dictionary tag is " + tag)
The dictionary tag is en_US
範例2:當。。。的時候enchant.request_dict()
方法在不傳遞任何參數的情況下執行,默認情況下它采用本地計算機語言的代碼。
# import the enchant module
import enchant
# instantiating the dictionary
# without passing any parameter
d = enchant.request_dict()
# finding the dictionary tag
tag = d.tag
print("The dictionary tag is " + tag)
The dictionary tag is en_IN
範例3:的enchant.request_dict()
如果沒有適當的字典,則該方法可能會失敗。在這種情況下,將顯示以下消息:
enchant.request_dict()
輸出:
Traceback (most recent call last):
File “”, line 1, in
enchant.request_dict()
File “C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\enchant\__init__.py”, line 272, in request_dict
return Dict(tag, self)
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.request_dict() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。