From: Joey J. <jo...@ca...> - 2011-11-14 21:50:49
|
My examples look like they are from a console window because my code uses a JTextArea to mimic a standard console window. Being a basic Swing component it naturally has support for UTF-8 as you have seen already. Concentrating on the "execfile('C:/temp/こんにちは/test.py')" issue first: I have verified that at least down to the InteractiveInterpreter.runsource() method my input string still correctly contains the correct characters. I have also verified that the CompilerFlags has source_is_utf8 set to True. I have not found the code yet that attempts to open the file that results in the IOError File not found exception. It should be noted that another part of the same application can correctly open and read files from the same directory using standard Java FileIO classes. joey -----Original Message----- From: ala...@gm... [mailto:ala...@gm...] On Behalf Of Alan Kennedy Sent: Monday, November 14, 2011 1:00 PM To: Joey Jarosz Cc: jyt...@li... Subject: Re: [Jython-users] UTF-8 support for interactive input [Joey] > Java 6u17 > sys.version_info == (2, 5, 2, 'final', 0) > Windows XP OK, so you're running on java 1.6, which means that you will benefit from Oti Humbels improvement on retrieving the console encoding[1], which you can access like this >>> sys.stdout.encoding cp437 For you, it should say "utf-8". > I am actually using the interpreter embedded in my Java application. I have > verified in my debugger that I am passing the UTF-8 characters down to > the interpreter without losing anything. > > If I access an attribute that I exposed from the Java level that returns a > string, it indeeds returns things correctly as shown below. > >>>> p.notes > '\u3053\u3093\u306b\u3061\u306f' > >>>> print p.notes > こんにちは OK, so this proves that the output encoding of whatever terminal is compatible with displaying UTF-8. But I'm still not clear you're executing this code. You say its running embedded in a java program, but the examples you post look like command line output? > But if I import the following function it does not work. > > # -*- coding: UTF-8 -*- > def testUTF8(): > print 'こんにちは' Try inserting a "print sys.stdout.encoding" before the other print statement. Alan. [1] http://bugs.jython.org/issue1568 |