첫 번째 Python 스크립트에서 추가 숫자가 인쇄되는 원인은 무엇입니까? (코드 페이지/유니코드 문제) (What is causing the extra number to be printed in my first Python script? (codepage/unicode issue))


문제 설명

첫 번째 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 Riverabobince)

참조 문서

  1. What is causing the extra number to be printed in my first Python script? (codepage/unicode issue) (CC BY‑SA 2.5/3.0/4.0)

#Python #codepages #utf-8 #unicode






관련 질문

Python - 파일 이름에 특수 문자가 있는 파일의 이름을 바꿀 수 없습니다. (Python - Unable to rename a file with special characters in the file name)

구조화된 배열의 dtype을 변경하면 문자열 데이터가 0이 됩니다. (Changing dtype of structured array zeros out string data)

목록 목록의 효과적인 구현 (Effective implementation of list of lists)

for 루프를 중단하지 않고 if 문을 중지하고 다른 if에 영향을 줍니다. (Stop if statement without breaking for loop and affect other ifs)

기본 숫자를 10 ^ 9 이상으로 늘리면 코드가 작동하지 않습니다. (Code fails to work when i increase the base numbers to anything over 10 ^ 9)

사용자 지정 대화 상자 PyQT5를 닫고 데이터 가져오기 (Close and get data from a custom dialog PyQT5)

Enthought Canopy의 Python: csv 파일 조작 (Python in Enthought Canopy: manipulating csv files)

학생의 이름을 인쇄하려고 하는 것이 잘못된 것은 무엇입니까? (What is wrong with trying to print the name of the student?)

다단계 열 테이블에 부분합 열 추가 (Adding a subtotal column to a multilevel column table)

여러 함수의 변수를 다른 함수로 사용 (Use variables from multiple functions into another function)

리프 텐서의 값을 업데이트하는 적절한 방법은 무엇입니까(예: 경사하강법 업데이트 단계 중) (What's the proper way to update a leaf tensor's values (e.g. during the update step of gradient descent))

Boto3: 조직 단위의 AMI에 시작 권한을 추가하려고 하면 ParamValidationError가 발생합니다. (Boto3: trying to add launch permission to AMI for an organizational unit raises ParamValidationError)







코멘트