Created
April 18, 2020 16:22
-
-
Save CarterTsai/2c3045dfcdc070b1b2221003a2d675e3 to your computer and use it in GitHub Desktop.
inline python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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