473,396 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.iso885915), and my terminal (rxvt-unicode)
is able to display those chars.

What am I missing?

Thanks.

--
Fabrice DELENTE
Jan 26 '07 #1
14 3322
On 2007-01-26, Fabrice DELENTE <fd******@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.iso885915), 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

Jan 26 '07 #2
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
Jan 26 '07 #3
On 2007-01-26, Fabrice DELENTE <fd******@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

Jan 26 '07 #4
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
Jan 26 '07 #5
Neil Cerutti <ho*****@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
http://invisible-island.net
ftp://invisible-island.net
Jan 27 '07 #6
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
Jan 27 '07 #7
On 2007-01-27, Thomas Dickey <di****@saltmine.radix.netwrote:
Neil Cerutti <ho*****@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
Jan 27 '07 #8
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
Jan 27 '07 #9
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("COLUMNS"))
lines=int(os.environ.get("LINES"))

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=$COLUMNS ./sort_entries.py

How come?

--
Fabrice DELENTE
Jan 27 '07 #10
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("COLUMNS"))
lines=int(os.environ.get("LINES"))

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=$COLUMNS ./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.

Jan 27 '07 #11
Try "export LINES COLUMNS" to set them as environment variables.

Thanks, it works. Didn't know that.

--
Fabrice DELENTE
Jan 27 '07 #12
In <45***********************@news.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:

http://excess.org/urwid/

Ciao,
Marc 'BlackJack' Rintsch
Jan 27 '07 #13
It's solved, it was a locale problem: I put

import locale

locale.setlocale(locale.LC_ALL,"fr_FR.iso8859-1")

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

Thanks all for your help.

--
Fabrice DELENTE
Jan 27 '07 #14
Fabrice DELENTE <fd******@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
http://invisible-island.net
ftp://invisible-island.net
Jan 27 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dominik Kaspar | last post by:
hello i'm wondering if i'm just too stupid for python or if i've missed something fundamentally important of its semantics. Why does the following program result in the TypeError: print_it()...
10
by: Dan Williams | last post by:
Ummmm... This is weird. Sorry if it's known about (how can it NOT be, I wonder?) but I haven't seen any reference to it anywhere. I'm running the latest Python (2.3.3) on Windows XP Pro, i386...
0
by: Harald Massa | last post by:
TOD DURCH ÜBERFRESSEN (Dead through overmunch) Python verschluckt sich an Kälbchen (Python chokes as little calf) http://www.spiegel.de/panorama/0,1518,307166,00.html
2
by: Aggelos I. Orfanakos | last post by:
Hello. Under Gentoo Linux, I issue: $ python timeit.py python: can't open file 'timeit.py' $ ls -al /usr/lib/python2.3/timeit.py -rw-r--r-- 1 root root 9833 Oct 19 02:17...
4
by: silasju | last post by:
Hello people! I think it is my first message here. Well, I would go to start a Delphi database program, but now my client want a program that runs in Linux. So I want to know your opinion: what...
5
by: Dr. Who | last post by:
So here it is: handle unbuffered output from a child process. Here is the child process script (bufcallee.py): import time print 'START' time.sleep(10) print 'STOP' In Perl, I do:...
0
by: ycollet | last post by:
Hello, I'm trying to write a program to send python statements to a python server via tcp and then get back results via a tcp connection. It nearly works ... but I'm totally lost with the...
2
by: enquiring mind | last post by:
-learning python with limited knowledge of linux. -get error msg 21 "file or directory does not exist" -running Suse linux 10. -haven't had a problem before - rebooted several times. -python...
2
by: psbasha | last post by:
Hi all, I am back again!!!. Whether Python can be used for Geograpical Information System (GIS)?.If so,can anybody help me which module of python it falls. Is thier any possible links...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.