這是我的一個按鈕點擊事件的Java代碼。我想要做的是將一個參數傳遞給我正在調用的python文件...但是我得到的錯誤爲args[0]
和args[1]
(cannot find symbol
)。將參數從Java傳遞到Python時出錯?
我該如何避免這個問題?如何將參數傳遞給我以這種方式調用的Python文件?
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
try {
PythonInterpreter.initialize(System.getProperties(), System.getProperties(), new String[0]);
PythonInterpreter interp = new PythonInterpreter();
interp.set("firstName", args[0]);
interp.set("lastName", 1);
interp.execfile("C:\\Users\\aswin-pc\\Desktop\\pythontest.py");
}
catch (Exception e) {
e.printStackTrace();
}
args沒有在這個方法中聲明,所以它不能被我引用。您想做什麼? args是數組持有Java程序的啓動參數嗎? – Djon
我想參數傳遞到從Java蟒蛇,告訴我沒有辦法做到這一點.. – eddy