

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

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

다음 코드 샘플은 Python(boto3) 기반 애필리케이션을 사용하여 AWS 리전에 발음 어휘를 저장하는 방법을 보여줍니다. 

이 작업에 대한 자세한 내용은 [https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html](https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html) API 참조를 참조하세요.

다음 사항에 유의하세요.
+ 로컬 어휘 파일 이름과 저장된 어휘 이름을 제공하여 코드를 업데이트해야 합니다.
+ 이 예제에서는 `pls`라는 하위 디렉토리에 사전 파일이 생성되었다고 가정합니다. 경로를 적절히 업데이트해야 합니다.

다음 코드 예제는 AWS SDK 구성 파일에 저장된 기본 자격 증명을 사용합니다. 구성 파일 생성에 대한 자세한 내용은 [설정AWS CLI](setup-cli.md)을 참조하세요.

이 작업에 대한 자세한 내용은 [https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html](https://docs.aws.amazon.com/polly/latest/dg/API_PutLexicon.html) API 참조를 참조하세요.



```
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))
```

