Windows XP unicode and escape sequences
Tim Roberts
timr at probo.com
Sat Dec 15 02:54:20 EST 2007
<jyoung79 at kc.rr.com> wrote:
>I mainly work on OS X, but thought I'd experiment with some Python code on XP. The
>problem is I can't seem to get these things to work at all.
>
>First of all, I'd like to use Greek letters in the command prompt window, so I was going to
>use unicode to do this. But in the command prompt, the unicode characters are displaying
>as strange looking characters. I tried installing the 'Bitstream Vera Sans Mono' font in hopes
>it had all the characters I needed but this didn't seem to work either. Is the problem the font?
>And if so, is there a certain font that has unicode '03B1', etc? Here's some code I tried:
It's not the font. (OK, it's partially the font.) To display Greek
characters to the console, your console session has to be set for a code
page that includes Greek characters.
>The next problem I'm having is I can't seem to color the text with ansi escape sequences. I
>added "device=%SystemRoot%\system32\ansi.sys" to the bottom of the CONFIG.NT file, and experimented with code like this:
>
>print chr(27) + "[36mTest" + chr(27) + "[0m"
>
>From what I found on-line, ascii character 27 seems to be the escape key I need, but I can't
>seem to get it to work. It just displays an arrow.
CONFIG.NT only affects 16-bit programs running in the NTVDM (the Virtual
DOS Machine).
32-bit console apps (which Python is) simply cannot use ANSI escape
sequences. You have to use the Win32 APIs to do color. There are
curses-like libraries available for Python. Or:
http://www.effbot.org/zone/console-handbook.htm
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list