我正在尝试将'Hello World‘插入到python文件中的def m(input)。但是它不起作用,我怎么解决它呢?
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')'
发布于 2021-03-14 13:34:51
callAttr
的参数应该单独传递,而不是作为一个单独的Python表达式。例如:
pyf.callAttr("m", "Hello world");
有关详细信息,请参阅callAttr
documentation和examples。
https://stackoverflow.com/questions/66621214
复制相似问题