

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# ListLexicon
<a name="ListLexiconSamplePython"></a>

下列 Python 程式碼範例使用 在本機 AWS 組態中指定的區域中 適用於 Python (Boto) 的 AWS SDK ，列出您帳戶中的語彙。如需建立組態檔的資訊，請參閱「[設定AWS CLI](setup-cli.md)」。

如需此操作的詳細資訊，請參閱 [https://docs.aws.amazon.com/polly/latest/dg/API_ListLexicons.html](https://docs.aws.amazon.com/polly/latest/dg/API_ListLexicons.html) API 的參考文章。

```
import sys

from boto3 import Session
from botocore.exceptions import BotoCoreError, ClientError

# Create a client using the credentials and region defined in the adminuser
# section of the AWS credentials and configuration files
session = Session(profile_name="adminuser")
polly = session.client("polly")

try:
    # Request the list of available lexicons
    response = polly.list_lexicons()
except (BotoCoreError, ClientError) as error:
    # The service returned an error, exit gracefully
    print(error)
    sys.exit(-1)

# Get the list of lexicons in the response
lexicons = response.get("Lexicons", [])
print("{0} lexicon(s) found".format(len(lexicons)))

# Output a formatted list of lexicons with some of the attributes
for lexicon in lexicons:
    print((u" - {Name} ({Attributes[LanguageCode]}), "
           "{Attributes[LexemesCount]} lexeme(s)").format(**lexicon))
```