I’m trying to use raw_input() with readline and utf-8 encoding (on OSX 10.6.8).
Imagine the following snippet:
import readline
while True:
try:
inp = raw_input('> ')
except EOFError:
break
This works except when trying to type non standard ASCII letters, say ‘å’ or ‘ä’. When doing this no input is written, I guess readline is filtering this somehow.
I then changed the input encoding using
sys.stdin = codecs.getwriter('utf-8')(sys.stdin)
Now typing ‘å’ and ‘ä’ works but it seems the readline functionality is no more.
Any ideas on how to make readline cope with unicode letters?
(Reposting as an answer): OSX ships with an inferior equivalent to readline called libedit (for licensing reasons, it can’t ship readline itself).
You can do
easy_install readlineto get GNU readline in Python on a Mac.This also causes a problem for IPython, which now displays an ugly warning if it detects that libedit is in use.