在Java中使用Python [英] Using Python from within Java

查看:122
本文介绍了在Java中使用Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

Java Python集成

我有一个用100%Java编写的大型现有代码库,但我想使用Python对于它的一些新部分。我需要做一些文本和语言处理,而且我更喜欢使用Python和像 NLTK 来做到这一点。

I have a large existing codebase written in 100% Java, but I would like to use Python for some new sections of it. I need to do some text and language processing, and I'd much rather use Python and a library like NLTK to do this.

我知道Jython项目,但看起来这代表了一种在Python中使用Java及其库的方法,而不是相反的方式 - am我错了吗?

I'm aware of the Jython project, but it looks like this represents a way to use Java and its libraries from within Python, rather than the other way round - am I wrong about this?

如果没有,那么在Java和Python之间进行接口的最佳方法是什么,这样(理想情况下)我可以在Python中调用一个方法并拥有结果返回Java?

If not, what would be the best method to interface between Java and Python, such that (ideally) I can call a method in Python and have the result returned to Java?

谢谢。

推荐答案


我知道Jython项目,但是
看起来这代表了

Python中使用Java及其库的方式,而不是另一种方式
round - 我错了吗?

I'm aware of the Jython project, but it looks like this represents a way to use Java and its libraries from within Python, rather than the other way round - am I wrong about this?

是的,你错了。您可以调用命令行解释器以使用Jyton运行python代码或< a href =http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html#using-jython-within-java-applications =nofollow noreferrer>使用Java中的python代码 。在过去,还有一个python-to-Java编译器,但它已经停止使用Jython 2.2

Yes, you are wrong. You can either call a command line interpreter to run python code using Jyton or use python code from Java. In the past there was also a python-to-Java compiler, but it got discontinued with Jython 2.2

这篇关于在Java中使用Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆