[Tutor] ipython / readline problem

Thorsten Kampe thorsten at thorstenkampe.de
Fri Dec 14 22:17:58 CET 2007


* Tiago Saboga (Thu, 13 Dec 2007 17:05:55 -0200)
> On Thu, Dec 13, 2007 at 07:41:08AM -0500, Kent Johnson wrote:
> > Tiago Saboga wrote:
> >> <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode
> >> character u'\xe7' in position 2: ordinal not in range(128)
> >>
> >> =======================================
> >>
> >> What's happening? Why do the readline methods accept a multibyte
> >> string ('ação') but not a unicode (u'ação')?
> >
> > I don't know what is happening with readline but this error is usually the
> > result of converting a Unicode string to a plain string without specifying
> > encoding, either explicitly by calling str() or implicitly such as in a
> > print statement:
> 
> I already knew that, but it helped somehow ;)
> 
> Apparently the problem is that ipython converts the input to unicode,
> while the readline module wants a string object. With single line
> input, ipython doesn't interfere with readline, but for multiline
> input, it updates readline's history, but it tries to to that with the
> unicode object. I've sent a patch to the ipython bug to reencode the
> string to sys.stdin.encoding before submitting it to readline.

For the new Ipython there's a new setting:

pyreadline.unicode_helper.pyreadline_codepage='utf8'



More information about the Tutor mailing list