将Java字符串参数传递给Jython interp

2024-05-19 02:30:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要将java字符串值(pdf文件的路径)传递给Jython解释器中的函数,即os.startfile(filename, "print")(其中filename是字符串)。所以我试着这样写:

 import org.python.util.PythonInterpreter;

 PythonInterpreter interpreter = new PythonInterpreter();
 interpreter.set("filename", fileDaStampare);
 interpreter.exec("import os");
 interpreter.exec("os.startfile(filename, \"print\")");

但当我执行java程序时,它会返回这个错误:

console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0. Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'startfile'

在Python解释器中如何执行这段代码?你知道吗


Tags: 文件字符串import路径pdfosjythonjava

热门问题