Java - Python : récuperer des events python
Bonjour,
J'essaye les interactions entre Java et Python :aie: J'ai donc installé Jython (avec une documentation plutôt pauvre).
J'arrive à lancer des scripts Python depuis mon code Java, et même à catcher des exceptions. Voilà le code:
Java
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
package python;
import org.python.core.PyException;
import org.python.util.PythonInterpreter;
public class pythonExec
{
public static void main(String[] args)
{
try
{
PythonInterpreter intepret = new PythonInterpreter();
intepret.execfile("c:\\hello.py");
}
catch (Exception e)
{
System.out.println("I got Python exception");
PyException pe = (PyException)e;
System.out.println(pe.value);
}
}
} |
Python
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
import exceptions
class MyException(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
if __name__ == "__main__":
print 'Start python script'
print 'Raise Exception'
raise MyException("Hello!")
print 'done' |
J'aimerai maintenant pouvoir lancer des events côté Python, et les récuperer côté java.
Une idée de comment faire ? (car j'arrive pas trop à saisir comment je vais pouvoir du côté Java m'abonner aux events python)
Merci
benoit