pyo3/examples/hello.rs

19 lines
524 B
Rust
Raw Normal View History

2015-04-18 22:39:04 +00:00
extern crate cpython;
use cpython::Python;
use cpython::ObjectProtocol; //for call method
fn main() {
let gil = Python::acquire_gil();
let py = gil.python();
2015-04-18 22:39:04 +00:00
let sys = py.import("sys").unwrap();
let version: String = sys.get(py, "version").unwrap().extract(py).unwrap();
let os = py.import("os").unwrap();
let getenv = os.get(py, "getenv").unwrap();
let user: String = getenv.call(py, ("USER",), None).unwrap().extract(py).unwrap();
println!("Hello {}, I'm Python {}", user, version);
}