The PythonInterpreter class is a standard wrapper for a Jython
interpreter for use embedding in a Java application.
cleanup
public void cleanup()
eval
public PyObject eval(String s)
Evaluate a string as Python source and return the result
s
- the string to evaluate
exec
public void exec(String s)
Execute a string of Python source in the local namespace
s
- the string to execute
exec
public void exec(PyObject code)
Execute a Python code object in the local namespace
code
- the code object to execute
execfile
public void execfile(String s)
Execute a file of Python source in the local namespace
s
- the name of the file to execute
execfile
public void execfile(java.io.InputStream s)
execfile
public void execfile(java.io.InputStream s,
String name)
get
public PyObject get(String name)
Get the value of a variable in the local namespace
name
- the name of the variable
get
public Object get(String name,
Class javaclass)
Get the value of a variable in the local namespace Value will be
returned as an instance of the given Java class.
interp.get("foo", Object.class)
will return the most
appropriate generic Java object.
name
- the name of the variablejavaclass
- the class of object to return
initialize
public static void initialize(Properties preProperties,
Properties postProperties,
String[] argv)
Initializes the jython runtime. This should only be called once, and
should be called before any other python objects are created (including a
PythonInterpreter).
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.
set
public void set(String name,
Object value)
Set a variable in the local namespace
name
- the name of the variablevalue
- the value to set the variable to.
Will be automatically converted to an appropriate Python object.
set
public void set(String name,
PyObject value)
Set a variable in the local namespace
name
- the name of the variablevalue
- the value to set the variable to
setErr
public void setErr(java.io.OutputStream outStream)
setErr
public void setErr(java.io.Writer outStream)
setErr
public void setErr(PyObject outStream)
setLocals
public void setLocals(PyObject d)
setOut
public void setOut(java.io.OutputStream outStream)
Set a java.io.OutputStream to use for the standard output stream
outStream
- OutputStream to use as output stream
setOut
public void setOut(java.io.Writer outStream)
Set a java.io.Writer to use for the standard output stream
outStream
- Writer to use as output stream
setOut
public void setOut(PyObject outStream)
Set the Python object to use for the standard output stream
outStream
- Python file-like object to use as output stream