DeleteLexicon - Amazon Polly
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

DeleteLexicon

以下 Python 代码示例使用Amazon SDK for Python (Boto) 删除在本地 Amazon 配置中指定的区域中的词典。该示例只删除指定的词典。在实际删除词典前,它会要求您确认要继续操作。

以下代码示例使用存储在 Amazon 软件开发工具包配置文件中的默认凭证。有关创建配置文件的信息,请参阅 步骤 2.1:设置 Amazon CLI

有关此操作的更多信息,请参阅 DeleteLexicon API 参考。

from argparse import ArgumentParser from sys import version_info from boto3 import Session from botocore.exceptions import BotoCoreError, ClientError # Define and parse the command line arguments cli = ArgumentParser(description="DeleteLexicon example") cli.add_argument("name", type=str, metavar="LEXICON_NAME") arguments = cli.parse_args() # Create a client using the credentials and region defined in the adminuser # section of the Amazon credentials and configuration files session = Session(profile_name="adminuser") polly = session.client("polly") # Request confirmation prompt = input if version_info >= (3, 0) else raw_input proceed = prompt((u"This will delete the \"{0}\" lexicon," " do you want to proceed? [y,n]: ").format(arguments.name)) if proceed in ("y", "Y"): print(u"Deleting {0}...".format(arguments.name)) try: # Request deletion of a lexicon by name response = polly.delete_lexicon(Name=arguments.name) except (BotoCoreError, ClientError) as error: # The service returned an error, exit gracefully cli.error(error) print("Done.") else: print("Cancelled.")