This is an official py03 example.
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
let py_app = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/app.py"));
let app: Py<PyAny> = PyModule::from_code(py, py_app, "", "")?
.getattr("test_function")?
.into();
app.call0(py)
})
my local app.py contains the following where the import is the rust module:
import GQLwrapper
print("running app.py")
def test_function:
print("running test function")
The rust call is running the file and ‘running app.py’ is printed but the test function itself is not being called?
>Solution :
let app: Py<PyAny> = PyModule::from_code(py, py_app, "", "")?
.getattr("test_function")?
.into();
is like python code
import app
app.test_function
That doesn’t execute the function. Instead, you should use call_method0
let app: Py<PyAny> = PyModule::from_code(py, py_app, "", "")?
.call_method0("test_function")?
.into();