Python - 소스 코드 파일 인코딩 지정

  • Post author:
  • Post category:
  • Post comments:0 Comments
  • Post last modified:September 15, 2005

Python Enhancement Proposals (PEPs) 문서 중 Defining Python Source Code Encodings는 각 Python 소스코드 파일에는 인코딩 타입을 명시해줄 것을 권고하고 있습니다.

인코딩 타입을 명시하지 않으면 파이썬은 ASCII 를 기본 인코딩으로 사용합니다. 소스 코드의 인코딩을 지정하려면 소스 파일의 첫번째 또는 두번째 줄에 다음과 같은 주석을 달아야 합니다.

         #!/usr/bin/python
         # -*- coding: <encoding name> -*-

예제)

         #!C:\\Python23\bin\python.exe
         # -*- coding: utf-8 -*-

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.