Package org.python.util
Class PythonInterpreter
java.lang.Object
org.python.util.PythonInterpreter
- Direct Known Subclasses:
InteractiveInterpreter
The PythonInterpreter class is a standard wrapper for a Jython
interpreter for use embedding in a Java application.
- Version:
- 1.0, 02/23/97
- Author:
- Jim Hugunin
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new Interpreter with an empty dictionaryPythonInterpreter
(PyObject dict) Create a new interpreter with the given dictionary to use as its namespacePythonInterpreter
(PyObject dict, PySystemState systemState) -
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanup()
Evaluate a string as Python source and return the resultvoid
Execute a string of Python source in the local namespacevoid
Execute a Python code object in the local namespacevoid
void
execfile
(InputStream s, String name) void
Execute a file of Python source in the local namespaceGet the value of a variable in the local namespaceGet the value of a variable in the local namespace Value will be returned as an instance of the given Java class.static void
initialize
(Properties preProperties, Properties postProperties, String[] argv) Initializes the jython runtime.void
Set a variable in the local namespacevoid
Set a variable in the local namespacevoid
setErr
(OutputStream outStream) void
void
void
void
setOut
(OutputStream outStream) Set a java.io.OutputStream to use for the standard output streamvoid
Set a java.io.Writer to use for the standard output streamvoid
Set the Python object to use for the standard output stream
-
Constructor Details
-
PythonInterpreter
public PythonInterpreter()Create a new Interpreter with an empty dictionary -
PythonInterpreter
Create a new interpreter with the given dictionary to use as its namespace- Parameters:
dict
- the dictionary to use
-
PythonInterpreter
-
-
Method Details
-
initialize
Initializes the jython runtime. This should only be called once, and should be called before any other python objects are created (including a PythonInterpreter).- Parameters:
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.
-
setOut
Set the Python object to use for the standard output stream- Parameters:
outStream
- Python file-like object to use as output stream
-
setOut
Set a java.io.Writer to use for the standard output stream- Parameters:
outStream
- Writer to use as output stream
-
setOut
Set a java.io.OutputStream to use for the standard output stream- Parameters:
outStream
- OutputStream to use as output stream
-
setErr
-
setErr
-
setErr
-
eval
Evaluate a string as Python source and return the result- Parameters:
s
- the string to evaluate
-
exec
Execute a string of Python source in the local namespace- Parameters:
s
- the string to execute
-
exec
Execute a Python code object in the local namespace- Parameters:
code
- the code object to execute
-
execfile
Execute a file of Python source in the local namespace- Parameters:
s
- the name of the file to execute
-
execfile
-
execfile
-
getLocals
-
setLocals
-
set
Set a variable in the local namespace- Parameters:
name
- the name of the variablevalue
- the value to set the variable to. Will be automatically converted to an appropriate Python object.
-
set
Set a variable in the local namespace- Parameters:
name
- the name of the variablevalue
- the value to set the variable to
-
get
Get the value of a variable in the local namespace- Parameters:
name
- the name of the variable
-
get
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.- Parameters:
name
- the name of the variablejavaclass
- the class of object to return
-
cleanup
public void cleanup()
-