Getting strange characters in the command prompt

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sebb

    Getting strange characters in the command prompt

    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?
  • Irmen de Jong

    #2
    Re: Getting strange characters in the command prompt

    sebb wrote:

    [...][color=blue]
    > ... 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?[/color]

    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

    Comment

    • Martin v. Loewis

      #3
      Re: Getting strange characters in the command prompt

      sebb wrote:
      [color=blue]
      > # -*- coding: cp1252 -*-
      > print "é à è"
      >
      > ... and I run it in the windows command prompt, I get strange
      > characters I didn't ask for.
      >[/color]
      [...][color=blue]
      > Can anyone help we with that problem?[/color]

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

      print u"é à è"

      Regards,
      Martin

      Comment

      • sebb

        #4
        Re: Getting strange characters in the command prompt

        Thanks a lot

        Comment

        Working...