예, 할 수 있습니다 완료되었습니다. 일반적으로 PythonInterpreter
개체를 만든 다음이를 사용하여 파이썬 클래스를 호출하면됩니다.
자바 :
import org.python.core.PyInstance;
import org.python.util.PythonInterpreter;
public class InterpreterExample
{
PythonInterpreter interpreter = null;
public InterpreterExample()
{
PythonInterpreter.initialize(System.getProperties(),
System.getProperties(), new String[0]);
this.interpreter = new PythonInterpreter();
}
void execfile(final String fileName)
{
this.interpreter.execfile(fileName);
}
PyInstance createClass(final String className, final String opts)
{
return (PyInstance) this.interpreter.eval(className + "(" + opts + ")");
}
public static void main(String gargs[])
{
InterpreterExample ie = new InterpreterExample();
ie.execfile("hello.py");
PyInstance hello = ie.createClass("Hello", "None");
hello.invoke("run");
}
}
파이썬 :
는 다음과 같은 예를 생각해
class Hello:
__gui = None
def __init__(self, gui):
self.__gui = gui
def run(self):
print 'Hello world!'
하지 아니, 그리고 점에 더 할 이유가 없다 같은 방식으로 . – Serdalis
답변이 귀하의 필요에 맞는가요? 문제가 해결 된 경우 대답을 선택하십시오. 그러면 질문에 답이 표시되지 않습니다. 감사 – Dropout