[Idle-dev] Re: [Python-Help] What was that regarding raw_input and Unicode? (fwd)

Skip Montanaro skip@pobox.com
Thu, 7 Mar 2002 19:13:46 -0600


--vhfKMF5ZMl
Content-Type: text/plain; charset=us-ascii
Content-Description: message body and .signature
Content-Transfer-Encoding: 7bit


The topic of raw_input failing when fed non-ASCII data came up on
python-help in the past day or two.  Alex Martelli wound up filing a bug
report against IDLE.  I figured the IDLEfork-sters might be interested in it
as well.

Cheers,

-- 
Skip Montanaro (skip@pobox.com - http://www.mojam.com/)


--vhfKMF5ZMl
Content-Type: message/rfc822
Content-Description: forwarded message
Content-Transfer-Encoding: 7bit

CONTENT-TRANSFER-ENCODING: quoted-printable
MIME-Version: 1.0
Content-Type: text/plain;
  charset="iso-8859-1"
Return-Path: <aleax@aleax.it>
Received: from cali-2.pobox.com (cali-2.pobox.com [64.71.166.115])
        by manatee.mojam.com (8.12.1/8.12.1) with ESMTP id g27GcS9A011614
        for <skip@manatee.mojam.com>; Thu, 7 Mar 2002 10:38:28 -0600
Received: from cali-2.pobox.com (localhost.localdomain [127.0.0.1])
        by cali-2.pobox.com (Postfix) with ESMTP id BAFB53E6B9
        for <skip@manatee.mojam.com>; Thu,  7 Mar 2002 11:38:27 -0500 (EST)
Delivered-To: skip@pobox.com
Received: from mx1.aruba.it (mx1.aruba.it [62.149.128.130])
        by cali-2.pobox.com (Postfix) with SMTP id 95A323E6DB
        for <skip@pobox.com>; Thu,  7 Mar 2002 11:38:26 -0500 (EST)
Received: (qmail 14717 invoked from network); 7 Mar 2002 16:39:51 -0000
Received: from unknown (HELO there) (213.45.32.5)
  by mx1.aruba.it with SMTP; 7 Mar 2002 16:39:51 -0000
Organization: None in Sight
X-Mailer: KMail [version 1.3.1]
References: <15495.36085.481502.529570@12-248-41-177.client.attbi.com>
In-Reply-To: <15495.36085.481502.529570@12-248-41-177.client.attbi.com>
Message-Id: <20020307163826.95A323E6DB@cali-2.pobox.com>
From: Alex Martelli <aleax@aleax.it>
To: skip@pobox.com, python-help@python.org
Subject: Re: [Python-Help] What was that regarding raw_input and Unicode?
Date: Thu, 7 Mar 2002 17:38:21 +0100

On Thursday 07 March 2002 04:53 pm, Skip Montanaro wrote:
> Folks,
>
> Raymond's note about modifying the site default encoding stuck in my =
head,
> and sure enough, Martin v. L=F6wis made a comment about it being a ba=
d thing
> to do.
>
> Can we reconstruct what was asked and answered to decide if there is =
a bug
> lurking in either raw_input() or IDLE that requires a bug report (thi=
s list
> is not archived)?  Attached is Martin's response to my question in c.=
l.py.

Hmmm... I was the one who answered Raymond, and I'm at fault for
not checking things through, I guess.  I've come to EXPECT trouble
with just about any non-ascii thing on sites which leave default
encoding to 'ascii'... sorry:-(.

I can confirm that raw_input works fine with non-ascii input on a Linux=
 KDE=20
Console, and on Windows 98 in both a textmode interactive interpreter a=
nd=20
IDLE (all Python 2.2).

With IDLE under Linux (Mandrake 8.1, and its released KDE), however:

Python 2.2 (#1, Dec 23 2001, 20:09:01)=20
[GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk)] on linux2
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> pal=F6
UnicodeError: ASCII encoding error: ordinal not in range(128)
>>> x=3Draw_input('say something funny: ')
say something funny: pal=F6
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in ?
    x=3Draw_input('say something funny: ')
TypeError: object.readline() returned non-string
>>>=20

I think Tk is returning a Unicode object (which can't be converted to
a string in this case with the default encoding 'ascii' as it includes =
a
non-ascii character), as it always does I believe; this is feeding
through to some readline method, and raw_input raises because
it can't get a string from that.  I'm not sure which component is at
fault or how IDLE is managing to work in the Windows 98 case.

Checking up in SF, I can't see any open bugs for IDLE and the 6
open bugs for Unicode don't seem to have anything to do with
this specific one.  So, I reported this -- it's now bug 527022.


Alex

--vhfKMF5ZMl--