Contents | Package | Class | Deprecated | Help
PREV | NEXT SHOW LISTS | HIDE LISTS

Class org.python.util.PythonInterpreter

java.lang.Object
    |
    +----org.python.util.PythonInterpreter

public class PythonInterpreter
extends java.lang.Object
The PythonInterpreter class is a standard wrapper for a JPython interpreter for use embedding in a Java application.


Constructor Summary
 PythonInterpreter()
Create a new Interpreter with an empty dictionary
 PythonInterpreter(org.python.core.PyObject dict)
Create a new interpreter with the given dictionary to use as its namespace
 

Method Summary
org.python.core.PyObject  eval(java.lang.String s)
Evaluate a string as Python source and return the result
void  exec(java.lang.String s)
Execute a string of Python source in the local namespace
void  execfile(java.lang.String s)
Execute a file of Python source in the local namespace
org.python.core.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.
org.python.core.PyObject  getLocals()
 
void  set(java.lang.String name, java.lang.Object value)
Set a variable in the local namespace
void  set(java.lang.String name, org.python.core.PyObject value)
Set a variable in the local namespace
void  setLocals(org.python.core.PyObject d)
 
 
Methods inherited from class java.lang.Object
 equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PythonInterpreter

public PythonInterpreter()
Create a new Interpreter with an empty dictionary

PythonInterpreter

public PythonInterpreter(org.python.core.PyObject dict)
Create a new interpreter with the given dictionary to use as its namespace
Parameters:
dict - the dictionary to use
Method Detail

eval

public org.python.core.PyObject eval(java.lang.String s) throws org.python.core.PyException
Evaluate a string as Python source and return the result
Parameters:
s - the string to evaluate

exec

public void exec(java.lang.String s) throws org.python.core.PyException
Execute a string of Python source in the local namespace
Parameters:
s - the string to execute

execfile

public void execfile(java.lang.String s) throws org.python.core.PyException
Execute a file of Python source in the local namespace
Parameters:
s - the name of the file to execute

getLocals

public org.python.core.PyObject getLocals()

setLocals

public void setLocals(org.python.core.PyObject d)

set

public void set(java.lang.String name,
                java.lang.Object value)
Set a variable in the local namespace
Parameters:
name - the name of the variable
value - the value to set the variable to. Will be automatically converted to an appropriate Python object.

set

public void set(java.lang.String name,
                org.python.core.PyObject value)
Set a variable in the local namespace
Parameters:
name - the name of the variable
value - the value to set the variable to

get

public org.python.core.PyObject get(java.lang.String name)
Get the value of a variable in the local namespace
Parameters:
name - the name of the variable

get

public 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. interp.get("foo", Object.class) will return the most appropriate generic Java object.
Parameters:
name - the name of the variable
javaclass - the class of object to return

Contents | Package | Class | Deprecated | Help
PREV | NEXT SHOW LISTS | HIDE LISTS