Python and Jython inconsistencies when encoding strings

Andre Michel Descombes amdescombes at qualicontrol.com
Fri Sep 6 06:30:03 EDT 2002


Hi,

I've noticed the following inconsistency between Python 2.1 and Jython 2.1 :

when I do the following in Python :

>>> s = u'£' # Alt-0163, pound sign
>>> print s

I get the following exception, which is a normal exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeError: ASCII encoding error: ordinal not in range(128)
>>>

I corrected this with using the encode function like this:

>>> print s.encode('latin-1')
£
>>>

now when I do the same thing in Jython 2.1 I get this:

>>> s = u'£' # Alt-0163, pound sign
>>> print s
£
>>>

and if I do:
>>> print s.encode('latin-1')

I get:

 Traceback (innermost last):
   File "<console>", line 1, in ?
 UnicodeError: latin-1 encoding error: ordinal not in range(256)
>>>

Does anybody know what is causing this inconsistency? Is there any way to
avoid it?

Thanks,

Andre





More information about the Python-list mailing list