python+ncurses: I can't display accents

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

    #1

    python+ncurses: I can't display accents


    Hello.

    I'm trying to display french characters (è -- that's e grave -- or à --
    agrave) in python 2.5, with the ncurses wrapper that comes it, and I can't.
    My locale is set correctly (fr_FR.iso88591 5), and my terminal (rxvt-unicode)
    is able to display those chars.

    What am I missing?

    Thanks.

    --
    Fabrice DELENTE
  • Neil Cerutti

    #2
    Re: python+ncurses: I can't display accents

    On 2007-01-26, Fabrice DELENTE <fdelente@mail. cpod.frwrote:
    I'm trying to display french characters (è -- that's e grave --
    or à -- agrave) in python 2.5, with the ncurses wrapper that
    comes it, and I can't. My locale is set correctly
    (fr_FR.iso88591 5), and my terminal (rxvt-unicode) is able to
    display those chars.
    What have you tried?

    --
    Neil Cerutti

    --
    Posted via a free Usenet account from http://www.teranews.com

    Comment

    • Fabrice DELENTE

      #3
      Re: python+ncurses: I can't display accents

      What have you tried?

      I've tried

      stdscr.addstr(0 ,0,"aéïoù")

      or

      stdscr.addstr(0 ,0,"leçon")

      The ASCII chars show correctly, but the accented characters don't, so I see
      'ao' or 'leon' on the screen.

      The term in which I display is 8-bit-able, so the problem is either on
      ncurses side, or on python side.

      I have

      #!/usr/local/bin/python
      #coding: iso8859-15

      at the top of my python file.

      --
      Fabrice DELENTE

      Comment

      • Neil Cerutti

        #4
        Re: python+ncurses: I can't display accents

        On 2007-01-26, Fabrice DELENTE <fdelente@mail. cpod.frwrote:
        >What have you tried?
        >
        I've tried
        >
        stdscr.addstr(0 ,0,"aéïoù")
        >
        or
        >
        stdscr.addstr(0 ,0,"leçon")
        >
        The ASCII chars show correctly, but the accented characters
        don't, so I see 'ao' or 'leon' on the screen.
        >
        The term in which I display is 8-bit-able, so the problem is
        either on ncurses side, or on python side.
        What happens when you try this?

        stdscr.addstr(0 ,0, u"leçon".encode ('iso8859-15'))

        I don't really expect it to work, but if anything will, that is
        it. Curses supports only ASCII and a some special symbol codes
        defined by curses.
        I have
        >
        #!/usr/local/bin/python
        #coding: iso8859-15
        Be sure to write your non-ASCII strings as unicode literals, and
        then encode them just before displaying or storing them
        somewhere.

        --
        Neil Cerutti

        --
        Posted via a free Usenet account from http://www.teranews.com

        Comment

        • Fabrice DELENTE

          #5
          Re: python+ncurses: I can't display accents

          What happens when you try this?
          stdscr.addstr(0 ,0, u"leçon".encode ('iso8859-15'))
          I don't really expect it to work
          And it doesn't...

          As support for 8-bit (and even unicode) is important for my script, is there
          any hope? Should I switch to slang instead of curses?

          --
          Fabrice DELENTE

          Comment

          • Thomas Dickey

            #6
            Re: python+ncurses: I can't display accents

            Neil Cerutti <horpner@yahoo. comwrote:
            I don't really expect it to work, but if anything will, that is
            it. Curses supports only ASCII and a some special symbol codes
            defined by curses.
            un - no. Curses supports whatever the flavor of curses you have does.
            Often that's the 8-bit flavor of ncurses, but the limitation is definitely
            in the python configuration.

            --
            Thomas E. Dickey
            Thomas Dickey develops/maintains widely-used tools and libraries for software development (diffstat, yacc, mawk) and terminals (ncurses, lynx, xterm)

            ftp://invisible-island.net

            Comment

            • Fabrice DELENTE

              #7
              Re: python+ncurses: I can't display accents

              My system is Linux, and the distribution is Slackware 10.1.

              I have

              /lib/libncurses.so.5 .4
              /lib/libncursesw.so. 5.4

              so I even have the wide-chars version available. Any hint on the python
              configuration? I didn't find any function that would allow the unrestricted
              display of 8-bit chars.

              --
              Fabrice DELENTE

              Comment

              • Neil Cerutti

                #8
                Re: python+ncurses: I can't display accents

                On 2007-01-27, Thomas Dickey <dickey@saltmin e.radix.netwrot e:
                Neil Cerutti <horpner@yahoo. comwrote:
                >I don't really expect it to work, but if anything will, that
                >is it. Curses supports only ASCII and a some special symbol
                >codes defined by curses.
                >
                un - no. Curses supports whatever the flavor of curses you
                have does. Often that's the 8-bit flavor of ncurses, but the
                limitation is definitely in the python configuration.
                Thanks for the clarification. I was going by the some Python
                documentation, but I did notice contradictory information in
                other discussion. The 8-bit ncurses is supposed to support
                iso-8859-1 through iso-8859-15, i.e., all the byle encodings. I
                don't know why Python's bindings don't work.

                --
                Neil Cerutti

                Comment

                • Fabrice DELENTE

                  #9
                  Re: python+ncurses: I can't display accents

                  To really be sure that the problem is when I use python, I tried in C:

                  #include <stdio.h>
                  #include <ncurses.h>

                  int main(void)
                  {
                  initscr(); /* Start curses mode */
                  // printw("àéïoù") ; /* Print Hello World */
                  addstr("àéïoù") ; /* Print Hello World */
                  refresh(); /* Print it on to the real screen */
                  getch(); /* Wait for user input */
                  endwin(); /* End curses mode */

                  return(0);
                  }

                  and both my tries (with printw, or with addstr) showed the 8-bot chars
                  correctly.

                  --
                  Fabrice DELENTE

                  Comment

                  • Fabrice DELENTE

                    #10
                    Re: python+ncurses: I can't display accents

                    Incidentally, I noticed something about the environment: in my script, I use
                    the LINES and COLUMNS environment vars that are set in my shell:

                    columns=int(os. environ.get("CO LUMNS"))
                    lines=int(os.en viron.get("LINE S"))

                    In the shell, I get

                    $ echo $LINES $COLUMNS
                    89 199

                    but python doesn't get these values. I have to start the script with

                    $ LINES=$LINES COLUMNS=$COLUMN S ./sort_entries.py

                    How come?

                    --
                    Fabrice DELENTE

                    Comment

                    • Carsten Haese

                      #11
                      Re: python+ncurses: I can't display accents

                      On 27 Jan 2007 07:43:59 GMT, Fabrice DELENTE wrote
                      Incidentally, I noticed something about the environment: in my
                      script, I use the LINES and COLUMNS environment vars that are set in
                      my shell:
                      >
                      columns=int(os. environ.get("CO LUMNS"))
                      lines=int(os.en viron.get("LINE S"))
                      >
                      In the shell, I get
                      >
                      $ echo $LINES $COLUMNS
                      89 199
                      >
                      but python doesn't get these values. I have to start the script with
                      >
                      $ LINES=$LINES COLUMNS=$COLUMN S ./sort_entries.py
                      >
                      How come?
                      There is a distinction between shell variables and environment variables. In
                      all likelihood, LINES and COLUMNS are shell variables, not environment
                      variables. Try "export LINES COLUMNS" to set them as environment variables.

                      HTH,

                      Carsten.

                      Comment

                      • Fabrice DELENTE

                        #12
                        Re: python+ncurses: I can't display accents

                        Try "export LINES COLUMNS" to set them as environment variables.

                        Thanks, it works. Didn't know that.

                        --
                        Fabrice DELENTE

                        Comment

                        • Marc 'BlackJack' Rintsch

                          #13
                          Re: python+ncurses: I can't display accents

                          In <45ba77a2$0$266 93$426a74cc@new s.free.fr>, Fabrice DELENTE wrote:
                          As support for 8-bit (and even unicode) is important for my script, is there
                          any hope? Should I switch to slang instead of curses?
                          Take a look at urwid:



                          Ciao,
                          Marc 'BlackJack' Rintsch

                          Comment

                          • Fabrice DELENTE

                            #14
                            Re: python+ncurses: I can't display accents

                            It's solved, it was a locale problem: I put

                            import locale

                            locale.setlocal e(locale.LC_ALL ,"fr_FR.iso8 859-1")

                            at the beginning of the script, and now the 8-bit-chars show up correctly.

                            Thanks all for your help.

                            --
                            Fabrice DELENTE

                            Comment

                            • Thomas Dickey

                              #15
                              Re: python+ncurses: I can't display accents

                              Fabrice DELENTE <fdelente@mail. cpod.frwrote:
                              My system is Linux, and the distribution is Slackware 10.1.
                              I have
                              /lib/libncurses.so.5 .4
                              /lib/libncursesw.so. 5.4
                              so I even have the wide-chars version available. Any hint on the python
                              configuration? I didn't find any function that would allow the unrestricted
                              display of 8-bit chars.
                              It's more complicated than that: python's loading "ncurses"
                              dynamically.

                              It doesn't matter much (to python) which one it loads, but it's
                              specifying the library name explicitly. At the same time, some other
                              packages (such as readline) are _separately_ loading the ncurses library
                              - and they also specify a library name. Rather than abstracting that
                              stuff out to another (more easily changed) level, it's embedded in the code.

                              If the initialization script is changed to load "ncursesw" then python
                              can use ncursesw without further change. There are a few patches to the
                              configuration that I've seen mentioned in the bug reports to enable
                              python to do this. Those are patches to python of course...

                              (this was a topic of discussion on this newsgroup about a year ago).

                              --
                              Thomas E. Dickey
                              Thomas Dickey develops/maintains widely-used tools and libraries for software development (diffstat, yacc, mawk) and terminals (ncurses, lynx, xterm)

                              ftp://invisible-island.net

                              Comment

                              Working...