Search code examples
javapythoncastingbooleanjython

How to convert PyObject to java boolean type


I would like to cast org.python.core.PyObject to java.lang.Boolean. Something similar to:

boolean i = ((Boolean) PyObject).booleanValue(); 

Solution

  • Just try the following:

    PyObject obj = interpreter.eval("True");
    boolean i = ((PyInteger) obj).asInt() != 0;