do you need jython for calling a python script from java?

samsamara

I have seen in answered here that if you want to call a python script from java, you can use jython as a option.

But have seen other answers as well saying, you can use Process or ProcessBuilder and call their exec or start methods to run the python script.

As I understand jython allows you to program python in you java code, but it allows you to call python scripts as well via, PythonInterpreter.execfile.

So I'm wondering what are my options if I want to call a python script (e.g. text processing script which uses nltk) from my java code and along with some arguments and return the results back to my java programme? which option should I use?

zapl

Jython is an implementation of the Python language for the Java platform (source)

You can simply use ProcessBuilder if there is a regular python script on a machine that has regular python installed. This saves you from having to include a whole python runtime in your java application. You can pass parameters quite easily, the returned text is a little trickier: See http://examples.javacodegeeks.com/core-java/lang/processbuilder/java-lang-processbuilder-example/ or other examples. Basically anything that the python program prints can be captured that way.

However if you don't like external dependencies and prefer shipping everything in a single application you can try jython. It has some limitations though since it doesn't come with all those modules and it seems it may have difficulties with C modules. Getting Python's nltk.wordnet module working for Jython looks like an explanation on how to get nltk to run with it. Arguments and return values should be simpler with jython since the integration is better. And if you want more than just printed text, Jython can even call into java code directly from python. That would give you interesting options for hybrid code.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

(Jython) Problems to run python script from java

From Dev

Jython - Calling Python Class in Java

From Java

Issue in calling Python code from Java (without using jython)

From Dev

Passing parameters from Java to Python using Jython

From Dev

How do I go from a bash script that calls a python script to a python script calling a bash script?

From Dev

How do I use Jython to script Java programs

From Dev

Python ImportError when calling Python script from Java

From Dev

Jython, stop script execution from inside of Java code

From Dev

Interface Jython script from Python3 module?

From Java

calling R script from java

From Dev

Calling python script from VBA

From Dev

Calling a SQL script from python

From Dev

Calling a shell script from python

From Dev

How do you successfully invoke gsutil rsync from a python script?

From Java

Jython, use only a method from Python from Java?

From Java

Calling Java from Python

From Dev

calling python from java

From Dev

Jython sending array of java File objects to java class from python

From Dev

calling python script from another script

From Dev

Calling methods of a Java subclass using Jython

From Java

Run a python function with arguments from java using jython

From Dev

Do you need to unsubscribe from @Output EventEmitter

From Java

Do you need to close a process opened by Java?

From Java

Do you need to close a process opened by Java?

From Dev

need guidance my vignette code in Jython/Python

From Javascript

Do you need text/javascript specified in your <script> tags?

From Java

Why do you need to put #!/bin/bash at the beginning of a script file?

From Dev

Jython with both Python and Java in Pydev

From Dev

Calling a ruby script from a java code

Related Related

HotTag

Archive