android python full integration
Is there a way to fully integrate Python with Java code on Android platform?
Yes, I saw the question about running Python on Android and Android Scripting Environment (ASE).
But that doesn't seem to be enough (correct me if I am wrong). I wanted to be able not only to invoke a Python script from within Java code, but have a full integration. The feature I need the most is the ability to have a state of execution of python code saved and be able to run several parts of code on demand against the same execution state.
On JavaSE I would rely on Jython. I believe its simplest example shows it all (and some other features too, like something I would call variable state introspection):
// http://www.jython.org/archive/21/docs/embedding.html
PythonInterpreter interp = new PythonInterprete开发者_JAVA技巧r();
System.out.println("Hello, brave new world");
interp.exec("import sys");
interp.exec("print sys");
interp.set("a", new PyInteger(42));
interp.exec("print a");
interp.exec("x = 2+2");
PyObject x = interp.get("x");
System.out.println("x: "+x);
System.out.println("Goodbye, cruel world");
Is it possible on Android? Is ASE a way to go?
ASE is probably the way to go.
I'm not a Jython expert, but I expect part of the problem with trying to go that route is that Android isn't really Java -- while the base language is the same, Android Java code does not share any of the "standard" Java libraries and it compiles into its own bytecode language.
Having said that, there is a defunct project for using Jython with Android. Its author has killed the project and is directing users to ASE:
http://code.google.com/p/jythonroid/
精彩评论