2
ok here是已經問過的問題,但答案似乎沒有多大幫助。我能夠使用jython運行python腳本,並在該問題中發佈的答案,但我無法傳遞變量...當我運行該程序錯誤說,沒有這樣的變量,如arg1 arg2和arg3 ...我是什麼做錯了?將變量傳遞給java的python腳本
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沒有宣佈