4

I try to call a python method from java, and made a very simple example. But I have an exception:

My py file (test.py)

def tmp():
    return "test!!!!!"

My java code

PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("import test");
PyObject someFunc = interpreter.get("tmp");
System.out.println(someFunc);
PyObject result = someFunc.__call__();
String realResult = (String) result.__tojava__(String.class);
System.out.println(realResult);

And I have this result, exception on line *PyObject result = someFunc.__call__();*, because someFunc is null

null 
Exception in thread "main" java.lang.NullPointerException   at
  com.testing.Test.test(Test.java:936)  at
  com.testing.Test.main(Test.java:96)

Any idea?

1
  • Use interpreter.get("test.tmp"); Commented Dec 13, 2012 at 10:33

1 Answer 1

2
interpreter.exec("from test import tmp");
PyObject someFunc = interpreter.get("tmp");
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.