當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Python enchant.list_languages()用法及代碼示例


Enchant是python中的一個模塊,用於檢查單詞的拚寫,並提供糾正單詞的建議。另外,給出單詞的反義詞和同義詞。它檢查字典中是否存在單詞。

enchant .dict_exists()

enchant.list_languages()是一種內置方法enchant模塊。它用於列出可用字典的語言。

用法: enchant.list_languages()

參數:沒有

返回:可用字典的語言代碼列表



範例1:
# import the enchant module 
import enchant 
  
# list the languages for which 
# dictionaries are available 
print(enchant.list_languages())

輸出:

[‘en_BW’, ‘en_AU’, ‘en_BZ’, ‘en_GB’, ‘en_JM’, ‘en_DK’, ‘en_HK’, ‘en_GH’, ‘en_US’, ‘en_ZA’, ‘en_ZW’, ‘en_SG’, ‘en_NZ’, ‘en_BS’, ‘en_AG’, ‘en_PH’, ‘en_IE’, ‘en_NA’, ‘en_TT’, ‘en_IN’, ‘en_NG’, ‘en_CA’]

範例2:驗證所有由生成的語言代碼enchant.list_languages()存在於enchant還是不使用enchant.dict_exists()

# import the enchant module 
import enchant 
  
for lang in enchant.list_languages():
    if enchant.dict_exists(lang):
        print("The dictionary for " + lang + " exists.") 
    else:
        print("The dictionary for " + lang + " does not exists.")

輸出:

The dictionary for en_BW exists.
The dictionary for en_AU exists.
The dictionary for en_BZ exists.
The dictionary for en_GB exists.
The dictionary for en_JM exists.
The dictionary for en_DK exists.
The dictionary for en_HK exists.
The dictionary for en_GH exists.
The dictionary for en_US exists.
The dictionary for en_ZA exists.
The dictionary for en_ZW exists.
The dictionary for en_SG exists.
The dictionary for en_NZ exists.
The dictionary for en_BS exists.
The dictionary for en_AG exists.
The dictionary for en_PH exists.
The dictionary for en_IE exists.
The dictionary for en_NA exists.
The dictionary for en_TT exists.
The dictionary for en_IN exists.
The dictionary for en_NG exists.
The dictionary for en_CA exists.

相關用法


注:本文由純淨天空篩選整理自Yash_R大神的英文原創作品 enchant.list_languages() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。