Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display utf-8 in windows console
    primarykey
    data
    text
    <blockquote> <p>I'm using Python 2.6 on Windows 7</p> </blockquote> <p>I borrowed some code from here: <a href="https://stackoverflow.com/questions/5419/python-unicode-and-the-windows-console">Python, Unicode, and the Windows console</a></p> <p><strong>My goal is to be able to display uft-8 strings in the windows console.</strong></p> <p>Apparantly in python 2.6, the </p> <blockquote> <p>sys.setdefaultencoding()</p> </blockquote> <p>is no longer supported</p> <p>However, I wrote reload(sys) before I tried to use it and it magically didn't error.</p> <p>This code will NOT error, but it shows funny characters instead of japanese text. <strong>I believe the problem is because I have not successfully changed the codepage of the windows console.</strong></p> <p>These are my attempts, but they don't work:</p> <pre><code>reload(sys) sys.setdefaultencoding('utf-8') print os.popen('chcp 65001').read() sys.stdout.encoding = 'cp65001' </code></pre> <p><strong>Perhaps you can use win32console to change the codepage?</strong> I tried the code from the website I linked, but it also errored from the win32console.. maybe that code is obsolete.</p> <p>Here's my code, that doesn't error but prints funny characters:</p> <pre><code>#coding=&lt;utf8&gt; import os import sys import codecs reload(sys) sys.setdefaultencoding('utf-8') sys.stdout = codecs.getwriter('utf8')(sys.stdout) sys.stderr = codecs.getwriter('utf8')(sys.stderr) #print os.popen('chcp 65001').read() print(sys.stdout.encoding) sys.stdout.encoding = 'cp65001' print(sys.stdout.encoding) x = raw_input('press enter to continue') a = 'こんにちは世界'#.decode('utf8') print a x = raw_input() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload