RE:Windows XP unicode and escape sequences

Discussion in 'Python' started by Guest, Dec 16, 2007.

  1. Guest

    Guest Guest

    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.
     
    Guest, Dec 16, 2007
    #1
    1. Advertising

  2. Guest

    MonkeeSage Guest

    Re: Windows XP unicode and escape sequences

    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
     
    MonkeeSage, Dec 17, 2007
    #2
    1. Advertising

  3. Guest

    Ross Ridge Guest

    Re: Windows XP unicode and escape sequences

    <> 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]
    -()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
    db //
     
    Ross Ridge, Dec 17, 2007
    #3
  4. Re: Windows XP unicode and escape sequences

    > 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
     
    Martin v. Löwis, Dec 19, 2007
    #4
  5. Re: Windows XP unicode and escape sequences

    > 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
     
    Martin v. Löwis, Dec 19, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. harrelson
    Replies:
    3
    Views:
    3,906
    Craig Ringer
    Dec 10, 2004
  2. slomo
    Replies:
    5
    Views:
    1,546
    Duncan Booth
    Dec 2, 2007
  3. Guest
    Replies:
    2
    Views:
    565
    Tim Roberts
    Dec 15, 2007
  4. Jeremy
    Replies:
    1
    Views:
    810
    Alex Willmer
    Jan 11, 2011
  5. Jeremy
    Replies:
    0
    Views:
    579
    Jeremy
    Jan 11, 2011
Loading...

Share This Page