Better solution to call Java methods that are reserved keywords in Python

16 views
Skip to first unread message

Vito Baggiolini

unread,
Aug 2, 2022, 2:55:13 AM8/2/22
to Py4J Support and Comments

Hello everybody,

I work at CERN where we use (py)spark and therefore py4j for our big data system called NXCALS (The Architecture of the Next CERN Accelerator Logging Service – Databricks).

Now we want to make our own Java APIs accessible to Python users. I’ve used py4j and it works very well in general. One situation however is not very well supported: calling Java methods with names that are reserved keywords in Python, such as or(), and(), or in().

I have seen a conversation in this forum (how to call a java method which the method name is a keyword in python (google.com)) which suggests to use getattr(), but IMO this is not very elegant.

Jpype, the "other" python-to-Java bridge solves this problem by automatically adding an underscore to the reserved method names, so that they can be called from Python as or_(), and_(), or in_().

I would be willing to make a contribution to this project to enable such a feature (and I don’t think it’s super-complicated), but of course, let’s start with some discussion here.

I’m looking forward to your replies!

Kind regards,
Vito Baggiolini

Reply all
Reply to author
Forward
0 new messages