make jython print utf-8?

Max Ziff ziff at cs.uchicago.edu
Fri Feb 7 01:05:03 EST 2003


As a jython newbie, with some java and I18N background, it appears to
me as though the stream that jython uses at the console for "print"
output is using the jvm's default encoding.  When I type:

>>> print u'\u05d0'

I get a single question mark.  That would be the same behavior I'd see
if I wrote a java program and did system.out.println("\u05d0").  I get
a question mark because system.out uses my local encoding by default. 
But if re-instantiate the output stream specifying UTF-8 explicitly, I
can get java to print in UTF-8.

Can I do something similar to make jython use a UTF-8 stream?  So if I
were to type the above, I would see two bytes, hex D7 and 90, the
UTF-8 representation of character 05d0 (Hebrew Alef).

Why?  I'm using jython for testing my classes that access a database
with Unicode in it, and I'd like to redirect the output of my script
to a file and view the file with a web browser or other UTF-8 viewer.

I'm also interested in the same thing for arbitrary files.  Is the
stdout stream in jython special in this way?

Thanks in advance!

Max




More information about the Python-list mailing list