【问题标题】:How do i get the result of a python function with py03我如何使用 py03 获得 python 函数的结果
【发布时间】:2022-11-20 20:50:12
【问题描述】:

我如何获得python函数的结果?

蟒蛇代码:

def test_function():
    print("running test function")
    "text content"

防锈代码:

Python::with_gil(|py| {
    let python_module: Py<PyAny> = PyModule::import(py, "model")?
        .call_method0("runner")?
        .into();
})

【问题讨论】:

  • 你不 return 来自 Python 函数

标签: rust


【解决方案1】:

我不确定我是否理解,你的意思是返回"text content"

def test_function():
   print("running test function")
   return "text content"

Python 函数默认返回 None


附言。我从来没有用过 Rust,所以我无法评论代码的第二部分(Python::with_gil(...))。

【讨论】:

    猜你喜欢
    • 2021-05-07
    • 1970-01-01
    • 1970-01-01
    • 2021-02-27
    • 2022-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多