Very strange unicode behaviour

S

Syver Enstad

Here's the interactive session

Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information..... try:
.... '\xe5'.find(u'')
.... except UnicodeError:
.... pass
........ func()
....
UnicodeError: ASCII decoding error: ordinal not in range(128)
It's weird that \xe5 throws and not \xe4 but even weirder that the
exception is not cleared so that the loop reports it.

Is this behaviour the same on Python 2.3?
 
T

Thomas Heller

Syver Enstad said:
Here's the interactive session

Python 2.2.2 (#37, Oct 14 2002, 17:02:34) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.... try:
... '\xe5'.find(u'')
... except UnicodeError:
... pass
...... func()
...
UnicodeError: ASCII decoding error: ordinal not in range(128)
It's weird that \xe5 throws and not \xe4 but even weirder that the
exception is not cleared so that the loop reports it.

Is this behaviour the same on Python 2.3?

No, it behaves correctly as it seems:

Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
Traceback (most recent call last):

Thomas
 
S

Syver Enstad

I have seem to isolate the behaviour:

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.
 
S

Syver Enstad

Thomas Heller said:
No, it behaves correctly as it seems:

That's a relief. See my later post to see why the first report I gave
was *very* confusing.
 
T

Thomas Heller

Syver Enstad said:
That's a relief. See my later post to see why the first report I gave
was *very* confusing.

It looks like an ignored exception somewhere without calling
PyErr_Clear().

Thomas
 
E

Erik Max Francis

Syver said:
I have seem to isolate the behaviour:


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@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.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@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.UnicodeError: ASCII decoding error: ordinal not in range(128)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top