Jython: How to import escaped Unicode and export utf-8?
Maurice Bauhahn
bauhahnm at clara.net
Sun Apr 29 15:27:49 EDT 2001
My problem is importing such escapes from a file. Can you do that? I note also that
you are using version 2.0 which is not documented to have the two hex character
limitation.
Cheers,
Maurice
Fredrik Lundh wrote:
> 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
--
Maurice Bauhahn
2 Meadow Way
Dorney Reach
MAIDENHEAD
SL6 0DS
United Kingdom
Home Tel: +44(0)1628 626068
Work Tel: +44(0)1932 878404
Home Email: bauhahnm at clara.net
Work Email: mbauhahn at brio.com
More information about the Python-list
mailing list