Write Python inline in your Rust code
docs.rs
docs.rs
The numpy crate helps if you need to convert large arrays to Python, as numpy does not store every element separately on the heap.
Total sidebar, this leads to one of my favourite programming language "quirks" - you can redefine the value of 1! http://hforsten.com/redefining-the-number-2-in-python.html
If I have many threads running Python code will it launch a new interpreter for each thread?
Does it use Python 2 or 3?
Thanks! I might actually use this sometime for scrap code that I'm writing to test stuff.
Python doesn't really do multithreading: https://wiki.python.org/moin/GlobalInterpreterLock
It uses Python 3 of course. Using Python 2 these days would be a crime.
Though I'd definitely advise wanting to do this to Do The Right Thing™ and just put each thing in its own file.
But using it to embed markup is really cool.
This is the ultimate combo making for the ultimate language. Inline html, inside javascript inside python inside rust. This is the future of programming.
I can't wait for the future.
I and others hate the pattern in python to write anything performant in C, Cython or some other language and write bindings for python. The python as binding language paradigmn doesn't work when all the stuff you want don't exist in performant languages.
TLDR; this fits the perfect use case for machine learning/data science, to use python only when necessary and hopefully migrate projects (parts of them atleast) to rust.
fn main() {
let data = vec![(4, 3), (2, 8), (3, 1), (4, 0)];
python! {
import matplotlib.pyplot as plt
plt.plot('data)
plt.show()
}
}
Source: https://twitter.com/m_ou_se/status/1118255841961025539Is it possible to build a static binary (including Python) with pyo3 in rust?