Skip to content

Instantly share code, notes, and snippets.

@CarterTsai
Created April 18, 2020 16:22
Show Gist options
  • Save CarterTsai/2c3045dfcdc070b1b2221003a2d675e3 to your computer and use it in GitHub Desktop.
Save CarterTsai/2c3045dfcdc070b1b2221003a2d675e3 to your computer and use it in GitHub Desktop.
inline python
#![feature(proc_macro_hygiene)]
use inline_python::python;
fn main() {
let who = "world";
let n = 5;
println!("== 1. Hello World ==");
python! {
for i in range('n):
print(i, "Hello", 'who)
print("Goodbye")
}
println!("== 2. Re-using Context ==");
let context = inline_python::Context::new();
python! {
#![context = &context]
name = "Carter"
}
python! {
#![context = &context]
print("context data=>", name)
}
println!("== 3. Show Python Version ==");
python! {
import sys
print(sys.version_info)
}
println!("== 3. Using Rust Variable ==");
let data = "hello rust variable";
python! {
print('data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment