Jython: How to import escaped Unicode and export utf-8?

Fredrik Lundh fredrik at pythonware.com
Sun Apr 29 08:43:02 EDT 2001


Maurice Bauhahn wrote:
> Hence, it appears that not only is it not possible to import \uXXXX, it is also
> appears impossible to handle any Unicode escape above the first 256
> characters...effectively ignoring Unicode altogether??? Is there something I am
> missing?

from the python documentation:

    \uxxxx - Character with 16-bit hex value xxxx (Unicode only)
    \Uxxxxxxxx - Character with 32-bit hex value xxxxxxxx (Unicode only)
    \xhh - ASCII character with hex value hh

in my copy of jython, given a sample.py file containing

    a = u"\u1780"

on a single line, I get:

    Jython 2.0 on java1.1.4
    >>> execfile("sample.py")
    >>> a
    u'\u1780'
    >>> len(a)
    1
    >>> a.encode("utf-8")
    '\341\236\200'
    >>> u"\u1780".encode("utf-8")
    '\341\236\200'

which is exactly what it's supposed to be (and exactly
what CPython 2.0 does)

Cheers /F





More information about the Python-list mailing list