MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / hello

Function hello

examples/hello.rs:8–24  ·  view source on GitHub ↗
(py: Python)

Source from the content-addressed store, hash-verified

6}
7
8fn hello(py: Python) -> PyResult<()> {
9 let sys = py.import("sys")?;
10 let version: String = sys.get(py, "version")?.extract(py)?;
11
12 let locals = PyDict::new(py);
13 locals.set_item(py, "os", py.import("os")?)?;
14 let user: String = py
15 .eval(
16 "os.getenv('USER') or os.getenv('USERNAME')",
17 None,
18 Some(&locals),
19 )?
20 .extract(py)?;
21
22 println!("Hello {}, I'm Python {}", user, version);
23 Ok(())
24}

Callers 1

mainFunction · 0.85

Calls 5

evalMethod · 0.80
importMethod · 0.45
extractMethod · 0.45
getMethod · 0.45
set_itemMethod · 0.45

Tested by

no test coverage detected