How to pass a tuple down into python code?

53 views
Skip to first unread message

Andrea Aime

unread,
Jun 18, 2020, 1:50:29 PM6/18/20
to Jep Project
Hi,
with with python code, I use "get" to fetch a tuple and get back a list of Objects.
However, when I try to set the tuple back into a variable in python code, at a later stage, using "set", the python
call using the set object fails:

"Cell suid must be a list or tuple. Got [N, 2]"

I'm guessing set created a list in python instead of a tuple? How do I force it do create a tuple instead?

Cheers
Andrea

Ben Steffensmeier

unread,
Jun 18, 2020, 4:43:43 PM6/18/20
to Jep Project
A Java List will become a PyJList in Python, which is just a wrapper around the Java object so that the list contents do not need to be copied until they are needed. PyJList is designed to be "duck typing" compatible with a python list. There is no way to have Jep directly perform any extra conversion in the set method, you will have to add logic in Python to perform any extra conversion. Since PyJList is a sequence you can just use the builtin tuple function like this:

jep.set("a", list);
jep
.exec("a = tuple(a)");

Ben

On Thursday, June 18, 2020 at 12:50:29 PM UTC-5, Andrea Aime wrote:
Hi,
with with python code, I use "get" to fetch a tuple and get back a list of Objects.
However, when I try to set the tuple back into a variable in python code, at a later stage, using "set", the pll hython
Reply all
Reply to author
Forward
0 new messages