how to call a java method which the method name is a keyword in python

19 views
Skip to first unread message

Ranger Tsao

unread,
Dec 9, 2016, 1:36:33 AM12/9/16
to Py4J Support and Comments
eg:

public class Test{
     public void and(){
           //do something
     }
}

how to call this method in python?


thanks all

Jonah Graham

unread,
Dec 9, 2016, 1:43:55 AM12/9/16
to Ranger Tsao, Py4J Support and Comments
Hi,

Instead of doing this which is the problem:

test_instance.and()

do this:

getattr(test_instance, "and")()

https://docs.python.org/3.6/library/functions.html#getattr

HTH
Jonah
~~~
Jonah Graham
Kichwa Coders Ltd.
www.kichwacoders.com
> --
> You received this message because you are subscribed to the Google Groups
> "Py4J Support and Comments" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to py4j+uns...@py4j.org.
> To post to this group, send email to py...@py4j.org.
> To view this discussion on the web visit
> https://groups.google.com/a/py4j.org/d/msgid/py4j/23ea4246-3bc7-4db3-960d-1fe075b13952%40py4j.org.

Ranger Tsao

unread,
Dec 10, 2016, 8:12:01 AM12/10/16
to Py4J Support and Comments
Thanks you!!! I will have a try

在 2016年12月9日星期五 UTC+8下午2:43:55,Jonah Graham写道:
Reply all
Reply to author
Forward
0 new messages