当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python enchant.request_dict()用法及代码示例


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。