Very strange unicode behaviour

Erik Max Francis max at alcyone.com
Fri Jan 16 15:13:12 EST 2004


Syver Enstad wrote:

> I have seem to isolate the behaviour:
> 
> >>> chr(127).find(u'')
> 0
> >>>
> >>> chr(128).find(u'')
> -1
> >>>
> UnicodeError: ASCII decoding error: ordinal not in range(128)
> >>>
> 
> Observe that the exception is first thrown on after execing a blank
> line, after calling find on a non ASCII string.
> 
> I'll test this on 2.3 when I get home from work.

I can indeed reproduce this bizarre behavior on 2.2.3.  The problem does
not occur in 2.3.3:

max at oxygen:~% python
Python 2.3.3 (#1, Dec 22 2003, 23:44:26) 
[GCC 3.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> chr(127).find(u'')
0
>>> chr(128).find(u'')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0:
ordinal not in range(128)
>>> 
max at oxygen:~% python2.2
Python 2.2.3 (#1, Jan  8 2004, 22:40:34) 
[GCC 3.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> chr(127).find(u'')
0
>>> chr(128).find(u'')
-1
>>> 
UnicodeError: ASCII decoding error: ordinal not in range(128)


-- 
 __ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/  \ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
\__/ The doors of Heaven and Hell are adjacent and identical.
    -- Nikos Kazantzakis



More information about the Python-list mailing list