|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.python.util.PythonInterpreter
public class PythonInterpreter
The PythonInterpreter class is a standard wrapper for a Jython interpreter for embedding in a Java application.
Constructor Summary | |
---|---|
PythonInterpreter()
Creates a new interpreter with an empty local namespace. |
|
PythonInterpreter(PyObject dict)
Creates a new interpreter with a specified local namespace. |
|
PythonInterpreter(PyObject dict,
PySystemState systemState)
|
Method Summary | ||
---|---|---|
void |
cleanup()
|
|
PyCode |
compile(Reader reader)
|
|
PyCode |
compile(Reader reader,
String filename)
|
|
PyCode |
compile(String script)
Compiles a string of Python source as either an expression (if possible) or a module. |
|
PyCode |
compile(String script,
String filename)
|
|
PyObject |
eval(PyObject code)
Evaluates a Python code object and returns the result. |
|
PyObject |
eval(String s)
Evaluates a string as a Python expression and returns the result. |
|
void |
exec(PyObject code)
Executes a Python code object in the local namespace. |
|
void |
exec(String s)
Executes a string of Python source in the local namespace. |
|
void |
execfile(InputStream s)
|
|
void |
execfile(InputStream s,
String name)
|
|
void |
execfile(String filename)
Executes a file of Python source in the local namespace. |
|
PyObject |
get(String name)
Returns the value of a variable in the local namespace. |
|
|
get(String name,
Class<T> javaclass)
Returns the value of a variable in the local namespace. |
|
PyObject |
getLocals()
|
|
PySystemState |
getSystemState()
|
|
static void |
initialize(Properties preProperties,
Properties postProperties,
String[] argv)
Initializes the Jython runtime. |
|
void |
set(String name,
Object value)
Sets a variable in the local namespace. |
|
void |
set(String name,
PyObject value)
Sets a variable in the local namespace. |
|
void |
setErr(OutputStream outStream)
|
|
void |
setErr(PyObject outStream)
|
|
void |
setErr(Writer outStream)
|
|
void |
setIn(InputStream inStream)
Sets a java.io.InputStream to use for the standard input stream. |
|
void |
setIn(PyObject inStream)
Sets a Python object to use for the standard input stream. |
|
void |
setIn(Reader inStream)
|
|
void |
setLocals(PyObject d)
|
|
void |
setOut(OutputStream outStream)
Sets a java.io.OutputStream to use for the standard output stream. |
|
void |
setOut(PyObject outStream)
Sets a Python object to use for the standard output stream. |
|
void |
setOut(Writer outStream)
|
|
static PythonInterpreter |
threadLocalStateInterpreter(PyObject dict)
Creates a new interpreter with the ability to maintain a separate local namespace for each thread (set by invoking setLocals()). |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PythonInterpreter()
public PythonInterpreter(PyObject dict)
dict
- a Python mapping object (e.g., a dictionary) for use
as the namespacepublic PythonInterpreter(PyObject dict, PySystemState systemState)
Method Detail |
---|
public static void initialize(Properties preProperties, Properties postProperties, String[] argv)
preProperties
- A set of properties. Typically
System.getProperties() is used. preProperties
override properties from the registry file.postProperties
- Another 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 override system properties and
registry properties.argv
- Command line arguments, assigned to sys.argv.public static PythonInterpreter threadLocalStateInterpreter(PyObject dict)
dict
- a Python mapping object (e.g., a dictionary) for use
as the default namespacepublic PySystemState getSystemState()
public void setIn(PyObject inStream)
inStream
- a Python file-like object to use as input streampublic void setIn(Reader inStream)
public void setIn(InputStream inStream)
inStream
- InputStream to use as input streampublic void setOut(PyObject outStream)
outStream
- Python file-like object to use as output streampublic void setOut(Writer outStream)
public void setOut(OutputStream outStream)
outStream
- OutputStream to use as output streampublic void setErr(PyObject outStream)
public void setErr(Writer outStream)
public void setErr(OutputStream outStream)
public PyObject eval(String s)
public PyObject eval(PyObject code)
public void exec(String s)
public void exec(PyObject code)
public void execfile(String filename)
public void execfile(InputStream s)
public void execfile(InputStream s, String name)
public PyCode compile(String script)
public PyCode compile(Reader reader)
public PyCode compile(String script, String filename)
public PyCode compile(Reader reader, String filename)
public PyObject getLocals()
public void setLocals(PyObject d)
public void set(String name, Object value)
name
- the name of the variablevalue
- the object to set the variable to (as converted to
an appropriate Python object)public void set(String name, PyObject value)
name
- the name of the variablevalue
- the Python object to set the variable topublic PyObject get(String name)
name
- the name of the variable
public <T> T get(String name, Class<T> 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 return
public void cleanup()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |