Python 3.0 Curses Unicode

Damian Johnson atagar1 at gmail.com
Sun Dec 28 18:06:18 EST 2008


Hi, I've switched to Python 3.0 for a new Japanese vocab quizzing
application due to its much improved Unicode support. However, I'm running
into an issue with displaying Unicode characters via curses. In Python 2.x a
simple hello-world looks like:

#!/usr/bin/python
# coding=UTF-8

import curses
import locale

locale.setlocale(locale.LC_ALL,"")

def doStuff(stdscr):
  message = u"hello わたし!"
  stdscr.addstr(0, 0, message.encode("utf-8"), curses.A_BLINK)
  stdscr.getch() # pauses until a key's hit

curses.wrapper(doStuff)

This works. However, when I try to come up with an equivalent for Python
3.0:

#!/usr/bin/python

import curses
import locale

locale.setlocale(locale.LC_ALL,"")

def doStuff(stdscr):
  message = "hello わたし!"
  stdscr.addstr(0, 0, message, curses.A_BLINK)
  stdscr.getch() # pauses until a key's hit

curses.wrapper(doStuff)

It fails (printing gibberish to the console). Anyone have a clue what I'm
doing wrong? Thanks! -Damian

PS. Is the "# coding=UTF-8" header meaningless in Python 3.0? Also, is
"locale.setlocale(locale.LC_ALL,"")" still necessary for getting curses to
provide Unicode support?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081228/ed134bec/attachment-0001.html>


More information about the Python-list mailing list