Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Windows XP unicode and escape sequences

Reply
Thread Tools

Windows XP unicode and escape sequences

 
 
Guest
Posts: n/a
 
      12-12-2007
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
 
Reply With Quote
 
 
 
 
John Roth
Guest
Posts: n/a
 
      12-14-2007
On Dec 12, 2:51 pm, <(E-Mail Removed)> 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:
>
> 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


 
Reply With Quote
 
 
 
 
Tim Roberts
Guest
Posts: n/a
 
      12-15-2007
<(E-Mail Removed)> 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, http://www.velocityreviews.com/forums/(E-Mail Removed)
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Convert unicode escape sequences to unicode in a file Jeremy Python 0 01-11-2011 11:39 PM
Convert unicode escape sequences to unicode in a file Jeremy Python 1 01-11-2011 10:36 PM
RE:Windows XP unicode and escape sequences Python 4 12-19-2007 09:52 AM
How to read strings cantaining escape character from a file and useit as escape sequences? slomo Python 5 12-02-2007 11:39 AM
converting html escape sequences to unicode characters harrelson Python 3 12-10-2004 08:15 AM



Advertisments