enchant.Dict() in Python
Enchant
is a module in python which is used to check the spelling of a word, gives suggestions to correct words. Also, gives antonym and synonym of words. It checks whether a word exists in dictionary or not.
enchant.Dict()
enchant.Dict()
is an inbuilt method of enchant
module. It is used to create a Dict object, which is the most important object in the enchant
t module. The Dict object represents the dictionary of a particular language.
Syntax : enchant.Dict(tag)
Parameter :
tag : the code of the language dictionary(optional)Returns : a Dict object
Example 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
Example 2 : When the enchant.Dict()
method is executed without passing any parameter in it, it by default takes the the code of the language of the local machine.
# 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
Example 3 : The enchant.Dict()
method may fail if the appropriate dictionary is not available. In that case the following message is printed:
enchant. Dict () |
Output :
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