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