473,387 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Windows XP unicode and escape sequences

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:

v = u'\u03B1\u03B2\u03B3'.encode('utf-8')
print v #just displays squares

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.

If anyone has any thoughts, I'd love to hear them.

Thanks!

Jay
Dec 12 '07 #1
2 3287
On Dec 12, 2:51 pm, <jyoun...@kc.rr.comwrote:
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:

v = u'\u03B1\u03B2\u03B3'.encode('utf-8')
print v #just displays squares
You've got two problems. First, you don't need to encode it; if the
command prompt window displayed your output after encoding it would
display the multi-byte form of your characters. You should just send
it a unicode object.

Second, check the .encoding attribute of the sys.stdout object.
Therein lies enlightenment about what the command prompt window will
accept.

No info on your other problem.

John Roth
>
If anyone has any thoughts, I'd love to hear them.

Thanks!

Jay
Dec 14 '07 #2
<jy******@kc.rr.comwrote:
>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, ti**@probo.com
Providenza & Boekelheide, Inc.
Dec 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: harrelson | last post by:
I have a list of about 2500 html escape sequences (decimal) that I need to convert to utf-8. Stuff like: 비 행 기 로 보 낼 거
2
by: Silvio Lopes de Oliveira | last post by:
Hello, I use Unicode in my program to enter data in Chinese into a nvarchar field. When inserting or updating records, my application does not use Unicode escape sequences but rather the Unicode...
5
by: Johannes | last post by:
Is it correct that Unicode characters with code points above 0x10FFFF are not supported by C# I have a hard time believing this since it would eliminate some Asian languages. If it is true, is...
5
by: Jonathan Seidner | last post by:
Hi, I have a program which contains a textbox, in this text box the user types this string: "\ub7c6\ub9d1\ubbd9\ubdc8\ubfcb\uc1b2\uc3a7\uc586\uc7a9\uc9b0\ucbfb" this is NOT a unicode string...
12
by: Onega | last post by:
Hi I create a simple win32 project (VC2003, windows2003(English) , and do simple paint in WM_PAINT message, when the project use multi-character set, it is OK. but when I change to UNICODE,...
4
by: Rehceb Rotkiv | last post by:
Hello, I have this little grep-like program: ++++++++++snip++++++++++ #!/usr/bin/python import sys import re
8
by: mario | last post by:
I have checks in code, to ensure a decode/encode cycle returns the original string. Given no UnicodeErrors, are there any cases for the following not to be True? unicode(s, enc).encode(enc)...
1
by: Eric S. Johansson | last post by:
I'm having a problem (Python 2.4) converting strings with random 8-bit characters into an escape form which is 7-bit clean for storage in a database. Here's an example: body =...
5
by: John Ztwin | last post by:
Hello, I have a file that contains ordinary text and some special charaters in Unicode escape sequences (\uxxxx). When I read the file using e.g. StreamReader Unicode escape sequences are not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.