Package weka.core.scripting
Class Jython
java.lang.Object
weka.core.scripting.Jython
- All Implemented Interfaces:
Serializable
,RevisionHandler
A helper class for Jython.
- Version:
- $Revision: 10203 $
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Object
deserializes the Python Object from the streamreturns the currently used Python InterpreterReturns the revision string.static Object
executes the specified method and returns the result, if anyexecutes the specified method on the current interpreter and returns the result, if any.static boolean
returns whether the Jython classes are present or not, i.e.static void
If no arguments are given, it just prints the presence of the Jython classes, otherwise it expects a Jython filename to execute.static Object
newInstance
(File file, Class<?> template) loads the module and returns a new instance of it as instance of the provided Java class template.static Object
newInstance
(File file, Class<?> template, File[] paths) loads the module and returns a new instance of it as instance of the provided Java class template.static Object
initializes and returns a Python Interpreter
-
Field Details
-
CLASS_PYTHONINERPRETER
the classname of the Python interpreter- See Also:
-
CLASS_PYTHONOBJECTINPUTSTREAM
the classname of the Python ObjectInputStream- See Also:
-
-
Constructor Details
-
Jython
public Jython()default constructor, tries to instantiate a Python Interpreter
-
-
Method Details
-
getInterpreter
returns the currently used Python Interpreter- Returns:
- the interpreter, can be null
-
invoke
executes the specified method on the current interpreter and returns the result, if any.- Parameters:
methodName
- the name of the methodparamClasses
- the classes of the parametersparamValues
- the values of the parameters- Returns:
- the return value of the method, if any (in that case null)
-
isPresent
public static boolean isPresent()returns whether the Jython classes are present or not, i.e. whether the classes are in the classpath or not- Returns:
- whether the Jython classes are available
-
newInterpreter
initializes and returns a Python Interpreter- Returns:
- the interpreter or null if Jython classes not present
-
newInstance
loads the module and returns a new instance of it as instance of the provided Java class template.- Parameters:
file
- the Jython module filetemplate
- the template for the returned Java object- Returns:
- the Jython object
-
newInstance
loads the module and returns a new instance of it as instance of the provided Java class template. The paths are added to 'sys.path' - can be used if the module depends on other Jython modules.- Parameters:
file
- the Jython module filetemplate
- the template for the returned Java objectpaths
- additional paths to add to "sys.path"- Returns:
- the Jython object
-
invoke
public static Object invoke(Object o, String methodName, Class<?>[] paramClasses, Object[] paramValues) executes the specified method and returns the result, if any- Parameters:
o
- the object the method should be called from, e.g., a Python InterpretermethodName
- the name of the methodparamClasses
- the classes of the parametersparamValues
- the values of the parameters- Returns:
- the return value of the method, if any (in that case null)
-
deserialize
deserializes the Python Object from the stream- Parameters:
in
- the stream to use- Returns:
- the deserialized object
-
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Returns:
- the revision
-
main
If no arguments are given, it just prints the presence of the Jython classes, otherwise it expects a Jython filename to execute.- Parameters:
args
- commandline arguments
-