public class PythonInterpreter
extends java.lang.Object
Constructor and Description |
---|
PythonInterpreter()
Create a new Interpreter with an empty dictionary
|
PythonInterpreter(PyObject dict)
Create a new interpreter with the given dictionary to use as its
namespace
|
PythonInterpreter(PyObject dict,
PySystemState systemState) |
Modifier and Type | Method and Description |
---|---|
void |
cleanup() |
PyObject |
eval(java.lang.String s)
Evaluate a string as Python source and return the result
|
void |
exec(PyObject code)
Execute a Python code object in the local namespace
|
void |
exec(java.lang.String s)
Execute a string of Python source in the local namespace
|
void |
execfile(java.io.InputStream s) |
void |
execfile(java.io.InputStream s,
java.lang.String name) |
void |
execfile(java.lang.String s)
Execute a file of Python source in the local namespace
|
PyObject |
get(java.lang.String name)
Get the value of a variable in the local namespace
|
java.lang.Object |
get(java.lang.String name,
java.lang.Class javaclass)
Get the value of a variable in the local namespace Value will be
returned as an instance of the given Java class.
|
PyObject |
getLocals() |
static void |
initialize(java.util.Properties preProperties,
java.util.Properties postProperties,
java.lang.String[] argv)
Initializes the jython runtime.
|
void |
set(java.lang.String name,
java.lang.Object value)
Set a variable in the local namespace
|
void |
set(java.lang.String name,
PyObject value)
Set a variable in the local namespace
|
void |
setErr(java.io.OutputStream outStream) |
void |
setErr(PyObject outStream) |
void |
setErr(java.io.Writer outStream) |
void |
setLocals(PyObject d) |
void |
setOut(java.io.OutputStream outStream)
Set a java.io.OutputStream to use for the standard output stream
|
void |
setOut(PyObject outStream)
Set the Python object to use for the standard output stream
|
void |
setOut(java.io.Writer outStream)
Set a java.io.Writer to use for the standard output stream
|
public PythonInterpreter()
public PythonInterpreter(PyObject dict)
dict
- the dictionary to usepublic PythonInterpreter(PyObject dict, PySystemState systemState)
public static void initialize(java.util.Properties preProperties, java.util.Properties postProperties, java.lang.String[] argv)
preProperties
- A set of properties. Typically System.getProperties() is used.postProperties
- An other set of properties. Values like python.home,
python.path and all other values from the registry files can
be added to this property set. PostProperties will override
system properties and registry properties.argv
- Command line argument. These values will assigned to sys.argv.public void setOut(PyObject outStream)
outStream
- Python file-like object to use as output streampublic void setOut(java.io.Writer outStream)
outStream
- Writer to use as output streampublic void setOut(java.io.OutputStream outStream)
outStream
- OutputStream to use as output streampublic void setErr(PyObject outStream)
public void setErr(java.io.Writer outStream)
public void setErr(java.io.OutputStream outStream)
public PyObject eval(java.lang.String s)
s
- the string to evaluatepublic void exec(java.lang.String s)
s
- the string to executepublic void exec(PyObject code)
code
- the code object to executepublic void execfile(java.lang.String s)
s
- the name of the file to executepublic void execfile(java.io.InputStream s)
public void execfile(java.io.InputStream s, java.lang.String name)
public PyObject getLocals()
public void setLocals(PyObject d)
public void set(java.lang.String name, java.lang.Object value)
name
- the name of the variablevalue
- the value to set the variable to.
Will be automatically converted to an appropriate Python object.public void set(java.lang.String name, PyObject value)
name
- the name of the variablevalue
- the value to set the variable topublic PyObject get(java.lang.String name)
name
- the name of the variablepublic java.lang.Object get(java.lang.String name, java.lang.Class javaclass)
interp.get("foo", Object.class)
will return the most
appropriate generic Java object.name
- the name of the variablejavaclass
- the class of object to returnpublic void cleanup()