【发布时间】:2020-09-18 08:43:07
【问题描述】:
如何将多个列表、值等从我的 Python 脚本返回到 Java 而不会以单个对象结束?现在我以一个包含两个返回值的 PyObject 结束,我还没有弄清楚如何在 Java 中再次划分它们。
Python:
import random
def calculations():
res1 = [33, 13, 20, 34]
list = [1,3,5,7]
res2 = random.choices(list, k=10000)
return res1, res2
Java:
if(!Python.isStarted())
Python.start(new AndroidPlatform(getActivity()));
Python py = Python.getInstance();
PyObject obj = py.getModule("main").callAttr("calculations");
# How to extract the different objects from obj? Tried the following without success.
List<PyObject> totList = obj.call(0).asList();
int[] data3 = obj.call(1).toJava(int[].class);
【问题讨论】:
-
如果您的应用程序崩溃,包含来自Logcat 的堆栈跟踪将非常有帮助。