【发布时间】:2017-02-18 16:19:10
【问题描述】:
好的,所以here 是已经提出的问题,但答案似乎没有多大帮助。我可以使用 jython 运行 python 脚本并在该问题中发布答案,但我无法传递变量...当我运行程序时,错误说没有像 arg1 arg2 和 arg3 这样的变量...我是什么做错了吗?
String[] arguments = {"myscript.py", "arg1", "arg2", "arg3"};
PythonInterpreter.initialize(System.getProperties(), System.getProperties(),arguments);
org.python.util.PythonInterpreter python = new org.python.util.PythonInterpreter();
StringWriter out = new StringWriter();
python.setOut(out);
python.execfile("myscript.py");
String outputStr = out.toString();
System.out.println(outputStr);
这里是python脚本
def myFunction(arg1,arg2,arg3):
print "calling python function with paramters:"
print arg1
print arg2
print arg3
myFunction(arg1,arg2,arg3)
现在错误显示 arg1 arg2 和 arg3 未声明
【问题讨论】: