0

I'm a C programmer learning Python 3 for the first time. This is my first script.

# -*- coding: utf-8 -*-
print ("Hello World!")
print ("Ä 0196, Ë 0203, Ï 0207, Ö 0214, Ü 0220, Ÿ 0159.")

Here is some setup and the output:

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>

It printed an extra "159." and a newline at the end. Why?

'py' with no arguments:

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.
>>>
Korgan Rivera
  • 495
  • 3
  • 9

1 Answers1

0

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.

bobince
  • 528,062
  • 107
  • 651
  • 834