FAQ
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

Search Discussions

  • John Roth at Dec 14, 2007 at 6:27 am

    On Dec 12, 2:51 pm, 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
  • Tim Roberts at Dec 15, 2007 at 7:54 am
    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.
  • Jyoung79 at Dec 16, 2007 at 11:28 pm
    Thank you John and Tim.

    With your help I found that the XP console code page is set up for 'cp437' and with a little bit of browsing I found that 869 is the code page for Modern Greek. After changing it to 869 that did the trick! Thanks very much for this advice.

    This brings up another question. If I run some Python code that starts off with 'os.system('cp869')' so it will change to the correct code page, then when it starts printing the Greek characters it breaks. But run the same Python code again and it works fine. Is there another way to do this so I can change over to the 869 code page and continue on with the Greek letters printing correctly?

    Thanks Tim for the info about the CONFIG.NT file as well as the curses-like info. I'll continue to research these.

    Thanks again!

    Jay
    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.

    From nejtak... Mon Dec 17 00:28:02 2007
    From: nejtak... (Troels Thomsen)
    Date: Mon, 17 Dec 2007 00:28:02 +0100
    Subject: int vs long
    Message-ID: <4765b49d$0$15883$edfadb0f@dtext01.news.tele.dk>


    The readFile function from the win32 package aparently really expect an
    integer :

    def inWaiting(self):
    """Returns the number of bytes waiting to be read"""
    flags, comstat = ClearCommError(self.__handle)
    return comstat.cbInQue

    ReadFile(h, s.inWaiting())

    My code crashes because inWaiting returns a long, not an int

    Why is that different on my machine and my collegues ? Have I or he
    installed a wrong version of a package?
    CPython 2.5.

    Was not expecting int<->long type problems in excactly python language.
    Is that because we are navigating so close to the win32 api that the types
    are more strictly enforced ?

    Thx in advance
    Troels
  • MonkeeSage at Dec 17, 2007 at 12:09 am

    On Dec 16, 5:28 pm, wrote:
    Thank you John and Tim.

    With your help I found that the XP console code page is set up for 'cp437' and with a little bit of browsing I found that 869 is the code page for Modern Greek. After changing it to 869 that did the trick! Thanks very much for this advice.

    This brings up another question. If I run some Python code that starts off with 'os.system('cp869')' so it will change to the correct code page, then when it starts printing the Greek characters it breaks. But run the same Python code again and it works fine. Is there another way to do this so I can change over to the 869 code page and continue on with the Greek letters printing correctly?

    Thanks Tim for the info about the CONFIG.NT file as well as the curses-like info. I'll continue to research these.

    Thanks again!

    Jay
    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.
    Try using the unicode switch ( cmd.exe /u ), rather than trying to set
    the codepage. See here:
    http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true

    Regards,
    Jordan
  • Ross Ridge at Dec 17, 2007 at 2:59 am
    wrote:
    This brings up another question. If I run some Python code that starts
    off with 'os.system('cp869')' so it will change to the correct code page,
    then when it starts printing the Greek characters it breaks. But run
    the same Python code again and it works fine.
    That's probably because the encoding of stdin, stdout, and stderr is set
    according to the code page of the console they're connected to (if any)
    when Python starts.
    Is there another way to do this so I can change over to the 869 code
    page and continue on with the Greek letters printing correctly?
    Unfortunately, you can't easily change the encoding of file object after
    it's been created. It's probably simpler convert Unicode strings to cp869
    before printing them instead of having Python do it automatically for you.

    Ross Ridge

    --
    l/ // Ross Ridge -- The Great HTMU
    [oo][oo] rridge at csclub.uwaterloo.ca
    -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
    db //
  • Martin v. Löwis at Dec 19, 2007 at 9:52 am

    This brings up another question. If I run some Python code that
    starts off with 'os.system('cp869')' so it will change to the correct
    code page, then when it starts printing the Greek characters it
    breaks. But run the same Python code again and it works fine. Is
    there another way to do this so I can change over to the 869 code
    page and continue on with the Greek letters printing correctly?
    You'll have to call SetConsoleOutputCP (see MSDN). Python does not
    directly expose that, so you'll have to use ctypes or PythonWin to
    call it.

    Regards,
    Martin

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedDec 12, '07 at 9:51p
activeDec 19, '07 at 9:52a
posts7
users6
websitepython.org

People

Translate

site design / logo © 2022 Grokbase