Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

Utility / tool to port java code directly to py4j python code?

I'm using py4j to port some java code directly to python. I'm wondering if there are any utilities or tools to automatically write the equivalent py4j code.

An example of the kind of code I'm porting would be as follows, where MyClass and MyOtherClass are java classes I have access to:

JAVA:

import com.mycompany.blah.MyClass;
import com.mycompany.blah.MyOtherClass;

MyClass foo = new MyClass();
MyOtherClass bar = new MyOtherClass(foo);

So the python code I'm looking for would look like:

PYTHON (Py4J):

from py4j.java_gateway import JavaGateway
from py4j.java_gateway import java_import

gateway = JavaGateway()
module = gateway.new_jvm_view()
java_import(module,'com.mycompany.blah.MyClass')
java_import(module,'com.mycompany.blah.MyOtherClass')

foo = module.MyClass()
bar = module.MyOtherClass(foo)

Thanks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...