我正在尝试返回要在Python中使用的字节列表:
fn example(_py: Python) -> PyResult<PyList> {
let result = some_function();
let elements_raw = vec![];
for entry in result {
elements_raw.push(PyBytes::new(_py, &entry.0));
}
let x: &[PyBytes] = &elements_raw;
let py_list = PyList::new(_py, x);
Ok(py_list)
}
但是,这一行抱怨是因为PyList
需要PyObject
:
let py_list = PyList::new(_py, x);
有没有办法将PyBytes
投射到PyObject
?有没有更好的方法来返回字节列表?