Python中的 enchant.request_dict()
Enchant
是Python中的一个模块,用于检查单词的拼写,给出正确单词的建议。此外,给出单词的反义词和同义词。它检查字典中是否存在单词。
附魔.request_dict()
附魔enchant.request_dict()
是enchant
模块的内置方法。它用于获取特定语言的字典对象。
Syntax : enchant.request_dict(tag)
Parameter :
tag : code of the language
Returns : a Dict object
示例 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
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。