我正在使用org.python.util.PythonInterpreter将Jython嵌入Java应用程序中.我使用的是Jython 2.5.2版.
我解释的python脚本包含UTF-8文字,因此我根据PEP-0263在脚本顶部添加了Python源代码编码:
# -*- coding: utf-8 -*-
Run Code Online (Sandbox Code Playgroud)
我的脚本编译如下:
String script = // load from file as a single String ...
PythonInterpreter pi = new PythonInterpreter();
PyCode code = pi.compile(script);
result = pi.eval(code);
Run Code Online (Sandbox Code Playgroud)
然而,Jython抱怨以下痕迹:
[java] ... : encoding declaration in Unicode string
[java] at org.python.core.ParserFacade.prepBufReader(ParserFacade.java:277)
[java] at org.python.core.ParserFacade.parseExpressionOrModule(ParserFacade.java:119)
[java] at org.python.util.PythonInterpreter.compile(PythonInterpreter.java:259)
[java] at org.python.util.PythonInterpreter.compile(PythonInterpreter.java:256)
[java] at org.python.util.PythonInterpreter.compile(PythonInterpreter.java:250)
Run Code Online (Sandbox Code Playgroud)
Jython是否支持脚本文件中的UTF-8?