Skip to content
Discussion options

You must be logged in to vote

After asking for some help to some rust folks, they found out that Python's module which essentially is most of the REPL behavior.

Here follows the solution code:

pub fn create_interpreter() -> PyResult<()> {
    let interp = Python::with_gil(|py| {
        let sys = py.import("sys")?;
        let version: String = sys.getattr("version")?.extract()?;

        let locals = [("os", py.import("os")?)].into_py_dict(py);
        let code = "os.getenv('USER') or os.getenv('USERNAME') or 'Unknown'";
        let user: String = py.eval(code, None, Some(&locals))?.extract()?;

        println!("Hello {}, I'm Python {}", user, version);

        py.run("import code; code.interact('')", None, None)

Replies: 1 comment

Comment options

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