

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

# PutLexicon
<a name="PutLexiconSamplePython"></a>

A amostra de código a seguir indica como usar aplicativos baseados em Python (boto3) para armazenar um léxico de pronúncia em uma região da AWS.

Para obter mais informações sobre esta operação, consulte a referência da API [https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html](https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html). 

Observe o seguinte:
+ Você precisa atualizar o código fornecendo um nome de arquivo de léxico local e um nome de léxico armazenado.
+ O exemplo pressupõe que você tenha arquivos de léxico em um subdiretório chamado `pls`. Você precisa atualizar o caminho conforme apropriado.

O exemplo de código a seguir usa as credenciais padrão armazenadas no arquivo de configuração do AWS SDK. Para obter informações sobre como criar o arquivo de configuração, consulte [Configurando o AWS CLI](setup-cli.md). 

Para obter mais informações sobre esta operação, consulte a referência da API [https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html](https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html). 



```
from argparse import ArgumentParser

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

# Define and parse the command line arguments
cli = ArgumentParser(description="PutLexicon example")
cli.add_argument("path", type=str, metavar="FILE_PATH")
cli.add_argument("-n", "--name", type=str, required=True,
                 metavar="LEXICON_NAME", dest="name")
arguments = cli.parse_args()

# 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")

# Open the PLS lexicon file for reading
try:
    with open(arguments.path, "r") as lexicon_file:
        # Read the pls file contents
        lexicon_data = lexicon_file.read()

        # Store the PLS lexicon on the service.
        # If a lexicon with that name already exists,
        # its contents will be updated
        response = polly.put_lexicon(Name=arguments.name,
                                      Content=lexicon_data)
except (IOError, BotoCoreError, ClientError) as error:
    # Could not open/read the file or the service returned an error,
    # exit gracefully
    cli.error(error)

print(u"The \"{0}\" lexicon is now available for use.".format(arguments.name))
```

