Skip to content

How to get a list of strings from Python to Rust #4830

Answered by LilyFoote
IdoPort asked this question in Questions
Discussion options

You must be logged in to vote

Hi @IdoPort!

Can you share the full code of your src\lib.rs file? That would make it easier to help you.

That said, I was able to modify your analyze_string function to:

#[pyfunction]
fn analyze_string(a: &str, b: Vec<String>) -> PyResult<bool> {
    Ok(false)
}

and it now compiles. You might find the table of conversions between Python and Rust types useful. In this case, I'm not certain why we don't have an implementation of FromPyObject for Vec<&str> - perhaps there's some technical limitation that makes it difficult.

Depending on your use case, you might also be able to use either:

use pyo3::types::PyString;

#[pyfunction]
fn analyze_string(a: &str, b: Vec<Bound<'_, PyString>>) -> PyR…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@IdoPort
Comment options

@davidhewitt
Comment options

Answer selected by IdoPort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants