Skip to content
Discussion options

You must be logged in to vote

I got something working thanks to another discussion:

#[pyclass]
struct LoggingStdout;

#[pymethods]
impl LoggingStdout {
    fn write(&self, data: &str) {
        println!("stdout from python: {:?}", data);
    }

    fn flush(&self) {}
}

Python::attach(|py| {
    let sys = py.import("sys")?;
    let stdout = Py::new(py, LoggingStdout)?;
    sys.setattr("stdout", stdout)?;
    let module = py.import("some_module")?;
    module
        .call_method1("render", (content, id.location()))?
        .extract::<SomeText>()
})

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pawamoy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant