Z
Z
zencd2012-07-23 20:10:12
Python
zencd, 2012-07-23 20:10:12

How to set PYTHONIOENCODING to get readable unicode text in cmd.exe?

Python 2.7.2, Windows 7, cmd.exe.

There is a string <type 'unicode'>. When you print it, the exception naturally falls out to the console. My actions:

SET PYTHONIOENCODING=windows-1251
The line is printed out, but in this form: "yayusyryufrёshЄ№ rtёyuёr" - that is, 866 is read as 1251 (or vice versa).

SET PYTHONIOENCODING=cp866 Exception
again.

SET PYTHONIOENCODING=utf-8
I get ╨Ъ╨╛╨╝╨┐╨╛╨╖╨╕╤В╨╛╤А╤L

Question: how to get readable text in the console? Preferably without iconv.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
marklarius, 2012-07-23
@marklarius

print x.encode("utf-8")

E
EndUser, 2012-07-24
@EndUser

reconfigure console on the fly via chcp command?

M
MikhailEdoshin, 2012-07-24
@MikhailEdoshin

Do you fundamentally need a Windows console? And then put cygwin, there is a console in the kit, with settings, including encodings.

M
Mithgol, 2012-07-24
@Mithgol

I will add to the above that a lot depends on whether dotted fonts were set in the console:
[screenshot of console properties]
If yes, then outputting text outside the character range of a single-byte encoding of such a font is not possible in any case, even if you use unicode and the console itself with the chcp 65001 command to switch to unicode. When the font itself simply lacks the desired characters.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question