PythonUtils

public class PythonUtils

Utilities for easier manipulation with Python through Jython.

Author:pipek

Methods

asNative

public static Object asNative(PyObject object)

Interpret the python object as a native Java one.

Returns:Object of the correct type. It has to be cast to be useful. Numbers converts to numbers (long or double). Dicts converts to TreeMap. Tuples and lists converts to Object[]. Dates converts to Date. NoneType converts to null. In case it does not know a type, it returns its string representation along with ! and type name. (e.g. ”!representation of my weird type{WeirdType}”)

getInterpreter

public static synchronized PythonInterpreter getInterpreter()

Get a single copy of python interpreter. More of them should not be needed.

invoke

public static PyObject invoke(PyObject object, String method, Map<String, PyObject> parameters)

Invoke a method on a Python object with named parameters. It calls invoke method present in Jython, it only allows easier manipulation with parameters (enabling this to be called with ParameterList).

newObject

public static PyObject newObject(String className, Map<String, PyObject> parameters)

Create a new instance of a named python class.