Re: unicode printing on Windows

On 2/9/2012 4:46 AM, BlueBird wrote:
Does anybody know how to fix problem 1 ? That way, I could at least
deal with programs that print UTF8 on stdout.
I'm pretty sure there isn't a way. cp65001 is supposed to be UTF-8, but
it doesn't work in my experience (I fed it some UTF-8 demo text and I
got garbage and beeping). Python 3.3 will support cp65001, 3.2 and below
do not.

Regarding point 2, I must admit even when I am the author of the
program, printing debug information (in unicode) on the stdout is a
really really tricky thing. Is there a recommendation on how to do
that properly ?
Use the logging module, perhaps? It has handled encoding issues
automatically, at least in my experience. In Python 3, you can convert a
string to bytes from one encoding, then convert to another encoding, but
Python 2 has things set up very differently (and my experience is with
py3k, so I can't help much).

CPython 3.2.2 | Windows NT 6.1.7601.17640

Relevant Pages

  • Re: pipeline encoding
    ... make any assumptions on the output encoding desired - ... Are there any command line option for telling python what encoding to use ... have presented - there are many print commands inside and it is not very ... Alternatively you can wrap stdout: ...
  • Re: Yet another unicode WTF
    ... #!/usr/bin/env python ... 'ascii' codec can't encode character u'\u03bb' in ... brain-damaged news reader that won't let me set the character encoding. ... Lots of programs detect whether stdout is a tty or not ) and adapt their output accordingly; ...
  • Re: Unicode conversion in print
    ... > the 'print' statement converts Unicode strings into the encoding ... It uses the encoding of you console. ... > print 'Python encoding:', sys.getdefaultencoding ... > If stdout is a terminal, ...
  • Re: the stupid encoding problem to stdout
    ... If two parties agree on an encoding, ... Python has agreed with stdout that it will send it characters encoded ...
  • Re: a question about Chinese characters in a Python Program
    ... Normally I'd entertain the possibility of bugs in Python, ... and that you indicate how the Unicode values are encoded as ... bytes (by specifying an encoding). ... EVERY SINGLE character expression with try ... ...