Jython: How to import escaped Unicode and export utf-8?
Maurice Bauhahn
bauhahnm at clara.net
Fri Apr 27 01:44:10 EDT 2001
Could you, Martin, or anyone else on the list, give a short Jython script
which imports escaped unicode from a file (presumeably using codecs) and
exports utf-8 to a file? My attempts at the same have not been successful.
Cheers,
Maurice
Martin von Loewis wrote:
> Maurice Bauhahn <bauhahnm at clara.net> writes:
>
> > My imports of escaped Unicode (u'\u1780' or '\u1780') end up in my lists
> > as:
> >
> > ["u'\\u1780'"]
>
> I very much doubt this. This looks more like the repr of a list,
> instead of like the list itself. That could be an incompatibility of
> repr for Unicode objects in Python, but I assume that the list is
> still build correctly.
>
> > and .write as u'\u1780'.
>
> In CPython, that would give an exception. You cannot write a Unicode
> object onto a stream without encoding it first.
>
> > From the command line I can get something useful by writing:
> >
> > u'\u1780'.encode('utf-8')
> >
> > but it does not appear to work within my jython script.
>
> That should work. How does it fail?
>
> Regards,
> Martin
--
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