Getting strange characters in the command prompt

Discussion in 'Python' started by sebb, Jan 7, 2004.

  1. sebb

    sebb Guest

    For information, I have windows xp (english edition).

    When I use special non-english characters (like é à è ...) in my
    python code, IDLE tells me to add a line like:

    # -*- coding: cp1252 -*-

    .... because of the presence of non-ASCII characters.

    When I write a script like the folowing:

    # -*- coding: cp1252 -*-
    print "é à è"

    .... and I run it in the windows command prompt, I get strange
    characters I didn't ask for.

    And when I write those non-English characters (é à è) directly in the
    command prompt, I get the correct characters.

    Can anyone help we with that problem?
    sebb, Jan 7, 2004
    #1
    1. Advertising

  2. sebb wrote:

    [...]
    > ... and I run it in the windows command prompt, I get strange
    > characters I didn't ask for.
    >
    > And when I write those non-English characters (é à è) directly in the
    > command prompt, I get the correct characters.
    >
    > Can anyone help we with that problem?


    Does executing

    chcp 1252

    before running your python program help?
    The windows console is not set to code page 1252 by default
    as far as I know, but some other windows-specific encoding.

    --Irmen
    Irmen de Jong, Jan 7, 2004
    #2
    1. Advertising

  3. sebb wrote:

    > # -*- coding: cp1252 -*-
    > print "é à è"
    >
    > ... and I run it in the windows command prompt, I get strange
    > characters I didn't ask for.
    >

    [...]
    > Can anyone help we with that problem?


    As Irmen explains, this is because cmd.exe uses code page 850
    (on your installation). You should write

    print u"é à è"

    Regards,
    Martin
    Martin v. Loewis, Jan 7, 2004
    #3
  4. sebb

    sebb Guest

    Thanks a lot
    sebb, Jan 7, 2004
    #4
    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. chrisdude911
    Replies:
    10
    Views:
    135,326
    srk289
    Mar 10, 2009
  2. gaurav kashyap
    Replies:
    2
    Views:
    604
    gaurav kashyap
    Oct 30, 2008
  3. gaurav kashyap
    Replies:
    3
    Views:
    671
    gaurav kashyap
    Oct 31, 2008
  4. Mel
    Replies:
    10
    Views:
    3,094
    Sailaja Appi
    Feb 13, 2009
  5. Vapor ..
    Replies:
    1
    Views:
    94
    Peña, Botp
    May 20, 2008
Loading...

Share This Page