lucene-pylucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andi Vajda <va...@apache.org>
Subject Re: call python from java - what strategy do you use?
Date Wed, 12 Jan 2011 22:54:43 GMT

  Hi Roman,

On Wed, 12 Jan 2011, Roman Chyla wrote:

> Thanks for the help, now I was able to run the java and loaded
> PythonVM. I then built the python egg, after a bit of fiddling with
> parameters, it seems ok. I can import the jcc wrapped python class and
> call it:
>
> In [1]: from solrpie_java import emql

Why are you calling your class EMQL ? (this name was just an example culled 
from my code).

> In [2]: em = emql.Emql()
>
> In [3]: em.javaTestPrint()
> java is printing
>
> In [4]: em.pythonTestPrint()
> just a test
>
> But I haven't found out how to call the same from java.

Ah, yes, I forgot to tell you how to pull that in.
In Java, you import that 'EMQL' java class and instantiate it by way of the 
PythonVM instance's instantiate() call:

             import org.blah.blah.EMQL;
             import org.apache.jcc.PythonVM;

             .............

             PythonVM vm = PythonVM.get();

             emql = (EMQL) vm.instantiate("jemql.emql", "emql");
             ... call method on emql instance just created ...

The instantiate("foo", "bar") method in effect asks Python to run
   "from foo import bar"
   "return bar()"

Andi..

Mime
View raw message