Python not displaying simplified Chinese properly in dos window
Question: I have a python script that prints chinese output on command line. It works
fine in eclipse. However, when I run it in dos window, it prints ? (question
marks) and garbage characters. Could it be because of big-5 vs gb encoding? if
so, how do I control it?

btw, I already installed the Asian character sets, which is why it works in
Eclipse

edit:combining chcp, encode('utf-8'), and setting the non-unicode handler, I
can now see the character, but a simple print results in a exception:

    
    
    chcp 65001
    Active code page: 65001
    
    Z:\src>c:\Python27\python.exe mobTest.py
    Traceback (most recent call last):
      File "mobTest.py", line 94, in <module>
        print u'哈哈'.encode('utf-8')
    IOError: [Errno 13] Permission denied
    


Answer: What is your system locale? `English (United States)`, for example, uses code
page 437 for the console, which doesn't support Chinese characters. `Chinese
(Simplified, PRC)` makes it possible to print Chinese to the console.

You can change the setting in `Region and Language` in Control Panel (Windows
7), `Administrative` tab and rebooting. After that, printing a _Unicode_
Chinese string to the console will work. You can even type in Chinese as an
IME will be available.

Changing the system locale will only affect the console and non-Unicode
programs. Most modern programs won't notice.

**Edit** : Example using Chinese PRC region and running in the Windows
console:

    
    
    Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print u'哈哈'
    哈哈
    >>> import sys
    >>> sys.stdout.encoding
    'cp936'
    

Example script using UTF-8 source encoding. Make sure to _save_ the source in
UTF-8, as declared by the `#coding` comment:

    
    
    # coding: utf-8
    print u'哈哈'
    print '哈哈' # this will be UTF-8 encoded, and NOT work
    

Execution:

    
    
    C:\>python x.py
    哈哈
    鍝堝搱
    

