Java使用jython.jar执行python代码
Java使用jython.jar执行python代码报错:ImportError: No module named encodings
代码如下:
public static void main(String[] args) {
String str = "42BB0F5C";
PythonInterpreter interp = new PythonInterpreter();
interp.exec("import struct");
interp.exec("from encodings import hex_codec");
interp.exec("str_value = struct.unpack('>f', '"+str+"'.decode('hex_codec'))[0]");
PyObject str_value = interp.get("str_value");
System.out.println(str_value.toString());
}