lucene-pylucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roman Chyla <roman.ch...@gmail.com>
Subject Re: call python from java - what strategy do you use?
Date Wed, 12 Jan 2011 23:10:24 GMT
Hi Andi,

Your help is great, thanks a lot! Without your detailed instructions,
I would not be able to figure it out - and the last bit with the
python...I should have thought before writing :-)

I call the class EMQL just because I was lazy to change it. But I will
do now that I understand little bit more. What I find very cool is the
fact, that if I build this extension the way you showed me, I can run
java from inside python, but also python from inside Java - and with
one jar and one compiled egg. Very handy. But as you said, evil is in
details, so I expect some bumps.

And about the thing with LFLAGS 'platform Python', also other
platforms will need something similar like Mac? I assume this is a mac
dynamic discovery of the libraries, will anything bad happen if I
changed the path of the Python now when the extension was built?


Cheers!

  roman

On Wed, Jan 12, 2011 at 11:54 PM, Andi Vajda <vajda@apache.org> wrote:
>
>  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