unicode printing on Windows

B

BlueBird

Hi,

The question is not totally related to Python but there is a strong
connection. Everytime that I try to debug some python programs under
Windows, I encounter the issue that things printed on the console
simply break the program because :
1. My windows console does not support UTF8
2. Things printed by the program on the stdout / stderr do not
necessarily use sys.getpreferredencoding() so break with UnicodeError.

Does anybody know how to fix problem 1 ? That way, I could at least
deal with programs that print UTF8 on stdout.

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 ?

Important information : I am using Python 2.5

cheers,

Philippe
 
A

Andrew Berg

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).
 
T

Terry Reedy

Hi,

The question is not totally related to Python but there is a strong
connection. Everytime that I try to debug some python programs under
Windows, I encounter the issue that things printed on the console
simply break the program because :
1. My windows console does not support UTF8

The IDLE shell (now) is friendlier to unicode, supporting the entire
BMP. So you may have more success loading into an IDLE editor and
running from there with F5. Or perhaps execfile in the shell (I never
tried this). Of course, import and pdb in the shell work. This all
depends on what 'debugging' means to you.
Important information : I am using Python 2.5

I don't know if IDLE was different then.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top