在Android Studio中使用Chaquopy在python文件中插入函数值

2024-06-16 05:39:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在python文件中的defm(input)中插入“helloworld”。但它不起作用我怎么能解决这个问题

main.py

def m(input):
    return input

MainActivity.java

if(!Python.isStarted())
    Python.start(new AndroidPlatform(this));

Python py = Python.getInstance();
PyObject pyf = py.getModule("main");
PyObject obj = pyf.callAttr("m('Hello World')");
text.setText(obj.toString());

这就是我犯的错误

com.chaquo.python.PyException: AttributeError: module 'main' has no attribute 'm('Hello World')'

Tags: 文件pyobjhelloworldinputreturnmain