문제 설명
첫 번째 Python 스크립트에서 추가 숫자가 인쇄되는 원인은 무엇입니까? (코드 페이지/유니코드 문제) (What is causing the extra number to be printed in my first Python script? (codepage/unicode issue))
저는 Python 3을 처음 배우는 C 프로그래머입니다. 이것은 나의 첫 번째 스크립트입니다.
# ‑*‑ coding: utf‑8 ‑*‑
print ("Hello World!")
print ("Ä 0196, Ë 0203, Ï 0207, Ö 0214, Ü 0220, Ÿ 0159.")
여기에 일부 설정 및 출력이 있습니다.
C:\Users\K\Desktop\Code\Python\Korgan\LearnPythonTheHardWay>chcp 65001
Active code page: 65001
C:\Users\K\Desktop\Code\Python\Korgan\LearnPythonTheHardWay>set PYTHONIOENCODING=utf‑8
C:\Users\K\Desktop\Code\Python\Korgan\LearnPythonTheHardWay>py ex1.py
Hello World!
Ä 0196, Ë 0203, Ï 0207, Ö 0214, Ü 0220, Ÿ 0159.
159.
C:\Users\K\Desktop\Code\Python\Korgan\LearnPythonTheHardWay>
추가 "159"가 인쇄되었습니다. 그리고 끝에 개행. 왜?
인수 없는 'py':
PS C:\Users\K\desktop\code\Python\Korgan\LearnPythonTheHardWay> py
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
참조 솔루션
방법 1:
The Windows console doesn't support code page 65001 and does a number of weird things when you try, due to underlying character‑counting bugs. This affects all applications using the C standard IO interfaces, including Python.
If you really, really need to get Unicode to the console it's possible to work around the problem by calling the Win32‑specific console APIs directly instead. See win_unicode_console.
(by Korgan Rivera、bobince)