views:

183

answers:

3

What are the basic nuts and bolts of calling (running? interpreting? what can you do?) Python code from a Java program? Are there many ways to do it?

+4  A: 

You can embed Jython within your Java application, rather than spawning off a separate process. Provided your library is compatible with Jython, that would seem the most logical place to start.

Brian Agnew
So are you saying that it's possible that a library might not be Jython-compatible?
jjujuma
Yes. I've edited my answer to provide a link to the Jython/CPython compatibility info
Brian Agnew
+2  A: 

Apart from embedding Jython as mentioned by Brian, you have these options as well.

Java 1.6 has inbuilt support for scripting. You can find more info here.

Spring also provides excellent support for scripting. JRuby, Groovy are supported by Spring Scripting. You can find info here.

Sathya
A: 

And if none of the other alternatives mentioned (Jython, Spring) work, you can always run an external CPython interpreter and communicate with the JVM through:

  • CORBA
  • Sockets
  • Pipes
  • Temporary files

Also maybe you would take a look at OpenOffice's UNO... I think it could be used outside the suite.

fortran