

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

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

以下 Python 代码示例使用AWS SDK for Python (Boto) 在本地 AWS 配置中指定的区域中列出您的账户中的词典。有关创建配置文件的信息，请参阅 [设置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))
```